Forum Discussion

jerryr125's avatar
jerryr125
Icon for Helper IV rankHelper IV
1 year ago
Solved

Matrix Visualization - Create Custom Total Column

Hi -  I would create a custom total column to appear at the end of my matrix visulalization.     Data from Data Source   Product Name Category Amount Ice Cream StartingInv 100 Ice C...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Thanks for the reply from rajendraongole1, please allow me to provide another insight:

    Hi, jerryr125 
    Thanks for reaching out to the Microsoft fabric community forum.

    Regarding the issue you raised, my solution is as follows:

    You can use the UNION() function combined with an index column for sorting:

    1.First, create a calculated table:

    Table 2 = 
    VAR f2 = ADDCOLUMNS(
            'Table',
            "index", CALCULATE(
                COUNTROWS('Table'),
                ALLEXCEPT(
                    'Table',
                    'Table'[Product Name]
                ),
                'Table'[Category] >= EARLIER('Table'[Category])
            )
        )
        VAR f1 = SUMMARIZE(
            'Table',
            'Table'[Product Name],
            "Category", "FinalInv",
            "Amount", VAR c1 = CALCULATE(
                SUM('Table'[Amount]),
                ALLEXCEPT(
                    'Table',
                    'Table'[Product Name]
                ),
                'Table'[Category] = "StartingInv"
            )
            VAR c2 = CALCULATE(
                SUM('Table'[Amount]),
                ALLEXCEPT(
                    'Table',
                    'Table'[Product Name]
                ),
                'Table'[Category] = "SoldInv"
            )
            VAR c3 = CALCULATE(
                SUM('Table'[Amount]),
                ALLEXCEPT(
                    'Table',
                    'Table'[Product Name]
                ),
                'Table'[Category] = "DefectInv"
            )
            RETURN
                c1 - c2 - c3,
            "index", 4
        )
        RETURN
            UNION(
                f2,
                f1
            )
    
    

    2.Next, sort based on the index column:

    3.Here's my final result, which I hope meets your requirements.

    4.For more details, please refer to:

    How to put the row and column subtotals in front o... - Microsoft Fabric Community

     

    Please find the attached pbix relevant to the case.

     

    Best Regards,

    Leroy Lu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.