Multi-column Sort in Ascending Order After Expansion

  • Last update:  2024-02-21
  • Overview

    Expected Effect

    You can use the SQL statement ORDER BY A, B in datasets to sort data first by A and then by B. However, you may not know how to achieve the effect of the multi-column sort in the designer. Therefore, this document introduces how to sort multiple columns through Sort After Expansion.

    For example, you want to sort data (after expansion) first by Sales Person and then by Sales Volume based on the same sales person, as shown in the following figure.

     1.png

    Implementation Method

    1. You can sort character data through INARRAY(Character data, SORTARRAY(UNIQUEARRAY(All expanded character data))).

    2. You can directly sort value data by its size.

    3. Finally, you can calculate the results of the above two steps to obtain new values and sort the new values.

    Example

    Data Preparation

    Create a general report, create a database query named ds1, and enter the SQL statement SELECT * FROM Sales_Volume where Region='North China'.

    Table Design

    1. Drag the fields in the dataset into cells from cell A2 to cell E2 respectively, as shown in the following figure.

     2.png

    2. Select cell A2 and set Data Setting to List, as shown in the following figure.

     3.png

    Sort After Expansion Setting

    Select cell A2, set Sort Basis to Formula and Sort Rule to Ascend, and enter the formula INARRAY(B2,SORTARRAY(UNIQUEARRAY(B2[!0])))*POWER(10, LEN(MAX(E2[!0])))+E2, as shown in the following figure.

    The combination calculations (involved in the formula) of cell B2 and cell E2 can help you to first sort data in cell B2 and then sort data in cell E2. The following table describes the formula.

    Formula
    Description

    SORTARRAY(UNIQUEARRAY(B2[!0]))

    The SORTARRAY function is used to sort data (text data) in cell B2.

    INARRAY(B2,SORTARRAY(UNIQUEARRAY(B2[!0])))

    Data in cell B2 has been sorted through the SORTARRAY function and saved as arrays.

    Positions of each text data in arrays are obtained through the INARRAY function.

    That is, by using the INARRAY function, the sorted texts can be converted into numbers, making it easier to perform combination calculations with data in cell E2 and then sort data in cell E2.

    *POWER(10, LEN(MAX(E2[!0])))

    This formula represents a fixed exponent. The result (obtained by the former formula) needs to be multiplied by the result (obtained by this formula) so that the number (representing the position of the text) can be increased.

    / If you do not increase the number (representing the position of the text) and only use small numbers such as 1, 2, and 3, the sort of values in cell B2 (after values in cell E2 are added) will be affected.

    +E2

    When the values in cell B2 are the same, the sum of values (obtained by adding the values in cell E2) is sorted in the group.

    That is, values in cell E2 are sorted after the sort of values in cell B2.

     4.png

    Effect Display

    On PC

    Save the template and click Pagination Preview. The effect is shown in section "Expected Effect."

    On Mobile Terminals

    The template can be previewed on both the DataAnalyst and HTML5 apps. The effect is shown in the following figure.

     5.png

    Template Download

    You can download the example template Multi-column Sort in Ascending Order After Expansion.cpt.


    Attachment List


    Theme: Report Application
    • 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