Forum Discussion

jerryr125's avatar
jerryr125
Helper 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 NameCategoryAmount
Ice CreamStartingInv100
Ice CreamSoldInv25
Ice CreamDefectInv5
CakeStartingInv200
CakeSoldInv50
CakeDefectInv10

 

 

Example Matrix Visualization:

 

Product NameStartingInvSoldInvDefectInvFinalInv
Ice Cream10025570
Cake2005010140

 

The Matrix Visualization is displaying:

Rows: Product Name

Columns: Category

Value: SUM of Amount

 

I would like to add the FinalInv column which is calculate by:

StatringInv - SoldInv - DefectInv

 

Any thoughts ? Thanks - Jerryr

  • 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.

6 Replies

    • jerryr125's avatar
      jerryr125
      Helper IV

      Hi   rajendraongole1  and thank you very much !

      How do you set the visualization so that the FinalInv column appears at the end of matrix visualization (see image below).  Any help is appreciated! Thanks - Jerry

       

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        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.

  • Hi   rajendraongole1  and thank you very much !

    How do you set the visualization so that the FinalInv column appears at the end of matrix visualization (see image below).  Any help is appreciated! Thanks - Jerry

     

     

    • rajendraongole1's avatar
      rajendraongole1
      Super User

      Hi jerryr125  -  Please follow the below steps.

      Steps to Move FinalInv to the End
      Reorder Columns in the Values Section:

      Open the Fields pane on the right side of the Power BI interface.
      Under your Matrix visualization:
      Ensure that FinalInv is listed last in the Values section.
      Drag and drop the FinalInv field below all the other fields in the Values section.
      Remove Unwanted Subtotals (Optional):

      If the subtotals for FinalInv are still appearing in every category, disable them:
      Select your Matrix visualization.
      Go to the Format Visual pane on the right.
      Navigate to the Subtotals section.
      Turn off Column subtotals or configure subtotals to exclude FinalInv.
      Check Column Layout:

      Ensure that the Category field is still in the Columns section in your Matrix visualization.
      The measure FinalInv should remain only in the Values section.