Cross-Level Accumulation

  • Last update:November 18, 2023
  • Overview

    iconNote:
    In FineReport V11.0.4 and later versions, users are advised to use the ACCSUM function to achieve cross-level accumulation.

    Application Scenario

    Cross-level accumulation is not achieved by calculating group accumulation, but by calculating the accumulation sum in the ascending order.

    For example, as shown in the following figure, cross-level accumulation is performed for the years 2010 and 2011.

     1.png

    Implementation Method

    Perform cross-level accumulation through the formula IF(&B2 > 1, C2 + D2[B2:-1], C2 + D2[A2:-1,B2:!-1]).

    Example

    Data Preparation

    Create a general report and create a data query named ds1. The SQL statement is as follows:

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

    FROM Order

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

     2.png

    Report Design

    Design the table as shown in the following figure. Drag the fields in ds1 to cells A2, B2, and C2. Perform cross-level accumulation for cell D2.

     3.png

    The formula for cell D3 is IF(&B2 > 1, C2 + D2[B2:-1], C2 + D2[A2:-1,B2:!-1]). The following table describes the formula.

    Formula
    Description

    IF(A, B, C)

    Represents a conditional expression. If A is true, returns B, otherwise, returns C.

    &B2 > 1

    Represents part of the conditional expression and checks whether the current value is the first month.

    D2[B2:-1]

    Represents the previous accumulation result. That is, represents the value of cell D2 corresponding to the previous cell B2 (last month).

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

    Represents the last accumulation result of the previous group. That is, represents the value of cell D2 corresponding to the last cell expanded from cell B2 in the previous cell A2 (last year).

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

    Represents that if &B2 > 1, from the second month, calculates the sum of the previous cumulative result plus the current month amount; if cell B2 is the first month, calculates the sum of the last cumulative result of the previous group plus the current month amount.

    Effect Preview

    Save the template and click Pagination Preview. Then the preview effect is shown in the following figure.

     4.png

    The template can be previewed on the APP/HTML5 terminal, as shown in the following figure.

     5.jpg

    Template Download

    For details, you can click to download Cross-Level Accumulation.cpt.


    Attachment List


    Theme: Report Features
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

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

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

    不再提示

    9s后關閉

    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