Dynamic Inter-Cell Computations

  • Last update:December 20, 2024
  • Overview

    Application Scenario

    Having learned about hierarchical coordinates, you can combine them with formula functions to conduct dynamic inter-cell computations, such as making comparisons, calculating proportions and comparisons with the previous period, and performing layer-by-layer accumulations, cross-layer accumulations, and conditional aggregations.

    Function Description

    Generally, traditional reporting tools only provide inter-cell computations within the same row and set computations for a certain group (or the whole set). The following table describes the deficiencies of the tools in several situations.

    • Cross-row computations (such as referencing data from the previous row): Typical applications include calculating the cumulative ratio and the comparison with the previous period.

    • Cross-group computations (such as comparisons with the previous year): The traditional tools do not apply to cross-group calculations.

    • Set operations: Only a few fixed functions (such as functions for retrieving the first place and calculating cumulative values) are provided.

    • The functions cannot be combined to form general set computations, such as retrieving the second place and calculating the cumulative product.

    • Some conditional computations (such as counting the number of values that are greater than the current value within a group, namely, data ranking)

    In FineReport, hierarchical coordinates are used to represent the positions of extended cells, which has effectively solved the above-mentioned problems regarding dynamic inter-cell computations.

    This document introduces how to write calculation expressions using hierarchical coordinates to conduct dynamic inter-cell computations through examples.

    Example One

    Expected Effect

    The following figure shows the effect.

    1.png

    FieldFormula

    Comparison

    Comparison = Amount Payable of the Current Month - Amount Payable of January.

    Each value extended from the cell is compared with the first value. In the example, the difference is calculated.

    Proportion

    Proportion = Amount Payable of the Current Month/Amount Payable of All Months.

    The proportion that each value extended from the cell occupies in the total amount is calculated.

    MoM

    The ratio of the data of each row to the data of the previous row is calculated.

    MoM (Development Speed) = Amount Payable of the Current Month/Amount Payable of   the Previous Month.

    Data Preparation

    Create a dataset named ds1, and enter the SQL query statement:

    SELECT STRFTIME('%m',"Order Date") AS Month,"Amount Payable"

    FROM Order

    WHERE STRFTIME('%Y',"Order Date")='2011'.

    2.png

    Report Design

    Design the report according to the description in the table.

    1. Enter the field title names in order (Month, Amount Payable, Comparison, Proportion, and Comparison with the Previous Period) in cells A1 to E1. Select cells A1 to E1, and select Header under Style > Style Setting > Theme, as shown in the following figure.

    3.png

    2. Drag the Month data column in the data set into cell A2, and the Amount Payable data column in the data set into cell B2. Select Summary from the drop-down list of Data Setting under Cell Element, as shown in the following figure.

    4.png

    3. Enter the formula B2 - B2[A2:1] in cell C2 to calculate the difference between each row of the data extended from cell B2 and the value of the first row, as shown in the following figure.

    5.png

    Formula description: For details about the formula description, see Relative and Absolute Coordinates.

    Formula
    Description

    B2

    Amount Payable of the Current Month

    B2[A2:1]

    Amount payable of January. That is to say, the value of cell B2 corresponding to the first value of column A2 is returned.

    B2 – B2[A2:1]

    Amount Payable of the Current Month – Amount Payable of January

    4. Enter the formula B2/SUM(B2[!0]) in cell D2 to calculate the proportion of the data of each row extended from cell B2 to the total value, as shown in the following figure.

    6.png

    The following table describes the formula.

    Formula
    Description

    B2

    Amount Payable of the Current Month

    B2[!0]

    All values (3949.70, 2293.65, 2310.21, 2116.69, 1346.74, and 4780.93) extended from cell B2 are returned.

    For details, see Common Formulas of Hierarchical Coordinates.

    SUM(B2[!0])

    All the returned values of cell B2 (namely the total amount payable of all months) are summarized.

    B2/SUM(B2[!0])

    The proportion of the monthly amount payable to the total amount is calculated.

    5. Enter the formula IF(&A2 > 1, B2/B2[A2:-1], 0) in cell E2 to calculate the ratio of the data of each row of extended from cell B2 to the data of the previous row, as shown in the following figure.

    7.png

    Formula description:

    Formula
    Description

    &A2

    The position of each value expanded from cell A2 is obtained.

    B2/B2[A2:-1]

    B2[A2:-1]: The amount payable of the previous month is returned.

    B2/B2[A2:-1]: Amount Payable of the Current Month/Amount Payable of the Previous Month

    IF(&A2 > 1, B2/B2[A2:-1], 0)

    Use the formula if it is not the cell with the serial number 1 (namely not the first cell). Output 0 if it is the first cell.

    Effect Display

    PC

    For details, see section "Expected Effect."

    Mobile Terminal

    The preview effects on the DataAnalyst app and the HTML5 terminal are the same, as shown in the following figure.

    8.jpg

    Example Two

    Expected Effect

    The following figure shows the effect.

    9.png

    Field
    Formula

    Layer-by-Layer  Accumulation

    Group by year, and calculate the cumulative total of the amounts payable of each month of each year.

    In the group report, the data of each group is accumulated row by row.

    Cross-Layer Accumulation

    The cumulative total of the amounts payable of all months and years is calculated.

    In the group report, all the data is accumulated row by row. The data continues to be accumulated based on the result of the previous group during the shift of groups.

    Conditional Summary

    The data that meets the specified conditions is summarized.

    Data Preparation

    Create a dataset named ds1, and enter the SQL query statement:

    SELECT STRFTIME('%Y',"Order Date") AS Year,STRFTIME('%m',Order Date) AS Month,"Amount Payable"

    FROM Order

    WHERE STRFTIME('%Y',"Order Date") IN ('2010','2011').

    10.png

    Report Design

    Design the report according to the description in the following table.

    Cell
    Operation

    A1   to E1

    Enter the field title names in order (Year, Month, Amount Payable, Layer-by-Layer Accumulation, and Cross-Layer Accumulation) in cells. Select A1 to E1, and select Header under Style > Style Setting > Theme.

    A2

    Drag the Year data column in the data set into the cell.

    B2

    Drag the Month data column in the data set into the cell.

    C2

    Drag the Amount Payable data column in the data set into the cell. Select Summary from the drop-down list of Data Setting under Cell Element, as shown in the following figure.

    D2

    Enter the formula C2 + D2[B2:-1]. The data expanded from cell C2 is cumulatively summarized row by row according to the year.

    E2

    Enter the formula IF(&B2 > 1, C2 + E2[B2:-1], C2 +   E2[A2:-1,B2:!-1]). The data expanded from cell C2 is cumulatively accumulated row by row. The data continues to be accumulated based on the cumulative result of the previous year during the shift of the year. Among the formula, B2:!-1 means acquiring the value of the last row of column B2 in the group. If it is B2:!-2, it means acquiring the value of the last but one row of column B2.

    A3 to C3

    Merge cells A3 to C3,  and enter the field title: Number of   Months with the Amount Payable Greater Than 2500. Set the left parent cell to A2, and select Header under Style > Style Setting > Theme.

    D3 to E3

    Merge cells D3 to E3,  and enter the formula COUNT(C2[!0]{A2 = $A2 && C2 > 2500}) to count the number of months with the amount payable greater than 2500.

    Formula description:

    1. Layer-by-Layer Accumulation: C2 + D2[B2:-1]

    Formula
    Description

    D2[B2:-1]

    The previous value of the layer-by-layer accumulation column of the current year is returned each time. For example, for January 2010, 0 is returned. For February 2010, the value of D2 (2837.94) corresponding to January is returned.

    C2 + D2[B2:-1]

    Amount Payable of the Current Month and Year + Value of the Cell of the Previous Layer-by-Layer Accumulation Column

    11.png

    2. Cross-Layer Accumulation: IF(&B2 > 1, C2 + E2[B2:-1], C2 + E2[A2:-1,B2:!-1])

    Formula
    Description

    &B2

    The position of each value expanded from cell B2 is obtained. 

    Note: The position of B2 is cumulatively counted from the beginning   according to the year of the left parent cell.
    For example, for January 2011, the returned value is 1. For January 2010, the returned value is also 1.

    For details, see Common Formulas of Hierarchical Coordinates.

    E2[B2:-1]

    The previous value of the layer-by-layer accumulation column of the current year is returned each time.

    For example, for January 2010, 0 is returned. For February 2010, the value of E2 (2837.94) corresponding to January is returned.

    For details, see Relative and Absolute Coordinates.

    E2[A2:-1, B2:!-1]

    For the data of each January, the cross-layer data of the last month of the previous year is returned.
    For example, the cross-layer accumulation data of January 2011 should be returned with the cross-layer accumulation data (15631.50) of June 2010.

    IF(&B2 > 1, C2 + E2[B2:-1], C2 + E2[A2:-1,B2:!-1])

    If it is not the first month of each year, the returned value is the sum of the previous value of the layer-by-layer accumulation column of the current year and the amount payable of the current month. If it is the first month of each year, the returned value is the sum of the layer-by-layer accumulation data of the last month of the previous year and the payable amount of the current month.

    12.png

    13.png

    3. Condition Summary: COUNT(C2[!0]{A2=$A2 && C2 > 2500})

    For details about the formula description, see Common Formulas of Hierarchical Coordinates.

    Formula
    Description

    A2 = $A2

    $A2 retrieves the value at the corresponding position after cell A2 is expanded.

    Determine whether the value of A2 is equal to the values expanded from A2.

    That is to say, judge whether they are in the same year (considering that the calculations are required to be performed by year).

    14.png

    A2 = $A2 && C2 > 2500

    The conditions that they are within the same year and the amount payable for each month is greater than 2500 are satisfied at the same time.

    C2[!0]{A2 = $A2 && C2 > 2500}

    The amount that satisfies the conditions of being within the same year and having an amount payable greater than 2500 for each month is obtained.

    For example, the values returned for the year 2010 are 2837.94, 3596.13, 2822.19, and 2580.17.

    COUNT(C2[!0]{A2 = $A2 && C2 > 2500})

    The returned amounts payable are counted.

    Effect Display

    PC

    For details, see section "Expected Effect."

    Mobile Terminal

    The preview effects on the DataAnalyst app and the HTML5 terminal are the same, as shown in the following figure.

    15.jpg

    Template Download

    For details, you can download the template Dynamic Inter-Cell Computation 1.cpt.

    For details, you can download the template Dynamic Inter-Cell Computation 2.cpt.

    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