Entry-Level Calculation Guide

  • Last update:April 14, 2025
  • Overview

    This document explains how to use the calculation function in FineReport. This document also explains when calculations are available and how to use the formula editor. If you are a new user of FineReport and not familiar with the functions, you can start by reading this document.

    Reason for Calculation Use

    You can create data based on the existing data in the data source and perform calculations on the data by calculation.

    You can perform complex analyses and create visual templates with the calculation results.

    Scenario for Calculation Use

    You can create data based on the existing data in the data source during the calculation.

    You can use functions to perform calculation in many scenarios. Such as: Splitting data.

    Converting field data types (for example, converting a string to a date)

    Filtering results

    Calculating proportions

    The following sections show scenarios where calculations are needed.

    Lack of Needed Data for Analysis in the Data Source

    The built-in data table OrderDetails_new in FRDemo contains Price, Quantity, Purchase Price, and Discount fields.If you need to calculate the Profit value of each order ID and the Average Profit value of all values of order IDs, you can use formulas similar to those shown in the following part to perform the calculation, as shown in the following figure.

    Profit: D2*(C2 - E2)*(1 - F2)

    Average profit: average(G2)

     2.png

    The following figure shows the result.

    3.png 

     

    Value Conversion in Components

    For example, you can enter the formula TODATE("2021/02/07 Wednesday", "yyyy/MM/ddEEE", "zh") to convert the string "2021/02/07 Wednesday" to a time type value, as shown in the following figure.

     4.png

    Configuration of Table Style and Color

    For example, you can set alternating row colors in a table.

    For details, see Interlace Color Change after Hidden Row.

    Positions for Function Calculation Use

    Function Use in the Formula Editing Box

    The following shows the positions in FineReport where you can use Formula Editor:

    Position Illustration

    Condition Attribute  

    Example: Changing the Background Color Across Rows/Columns.

    01.png

    Data Dictionary 

    Example: section "Formula" in Data Dictionary.

    02.png

    Sifting and Filtering 

    04.png

    05.png

    Data Entry Submission Condition 06.png
    Chart Title 07.png
    Chart Axis 08.png
    Cells as Chart Data Sources 09.png
    Report Header and Footer 010.png
    Cell Content Prompt 011.png

    Function Use in the SQL Editing Box

    Using common functions in SQL statements

    You can put formulas in ${} when using formulas in SQL statements. For example, the following SQL statement returns all content of the table if the parameter is null.

    SELECT * FROM Order WHERE 1=1 ${if(len(area) == 0,"","and supplier area = '" + area + "'")} ${if(len(province) == 0,"","and supplier province = '" + province + "'")}

    iconNote:
    You can use custom functions in SQL statements, but the View Executed SQL function is unavailable in this case.

    Parameter/Formula Description
    area and province  Custom parameters
    if(len(area) == 0,"","and supplier area = '" + area + "'") 

    If the value of the area parameter is not null (namely, len(area)!=0), the IF clause will be executed. For example, if the value of area is East China, then the execution result of the IF clause is and the supplier area = 'East China',. The SQL statement concatenated with the IF clause is as follows.

    SELECT * FROM Order where 1=1 and supplier area='East China' and supplier province='Jiangsu'

    Using SQL functions in SQL Statements

    SQL statements are actually strings. Therefore, you can use an SQL statement from the database as a string to get the numbers. In this case, you can use SQL functions such as the following formula:

    =sql("FRDemo","SELECT * FROM Sales_volume ",1,1) returns East China.

    Meanwhile, you can also use this string in SQL formulas to be executed as a string. So you can use SELECT * FROM where area='${sql(“FRDemo”, “SELECT * FROM Sales_volume ‘,1,1)}’ to create a dataset.

    Alternatively, you can use SELECT * FROM  where area='East China'. 

    Function Use in the JS Editing Box

    Attachment List


    Theme: Report Features
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy