cancel
Showing results for 
Search instead for 
Did you mean: 

Matrix Measure Total Triple Threat Rock & Roll

Super User IV
9464 Views
Super User IV
Super User IV

Matrix Measure Total Triple Threat Rock & Roll

While it would be a bit presumptuous to presume that any single formula could account for all possible measure total situations, the following pattern is presented for handling matrix measure values as well as subtotals and grand totals. This pattern has the added flexibility of being able to handle the same or different aggregation calculations at all three levels. In the example provided, the "normal" aggregation is MIN while at the the subtotal level it is the AVERAGE of those MIN values. At the grand total level, it is the MAX of the AVERAGE of the subtotals.

 

Overall, this pattern provides extreme flexibility and can be extended to any number of level subtotals.

 

The main assumption is that there is a "normal aggregation" measure that one is wishing to display in a matrix with correct subtotals and grand total. In this example, the formula for this normal aggregation is "Normal Aggregation = MIN('Table'[Occupancy %]).

 

 

MM3TR&R = 
VAR __Category1 = MAX([Category1])
VAR __tmpTable =  SUMMARIZE(
                      ALLSELECTED('Table'),
                      'Table'[Category1],
                      'Table'[Category2],
                      "Aggregation",[Normal Aggregation]
                  )
VAR __SubTotal =  
    AVERAGEX(
        FILTER(
            __tmpTable,
            'Table'[Category1]=__Category1
        ),
        [Aggregation]
    )
VAR __GrandTotal =  
            MAXX(
                GROUPBY(
                    __tmpTable,
                    [Category1],
                    "GTAggregation",
                    AVERAGEX(CURRENTGROUP(),[Aggregation])
                ),
                [GTAggregation]
            )
RETURN IF(
            HASONEVALUE('Table'[Category1]) && HASONEVALUE('Table'[Category2]),
            [Normal Aggregation],
            IF(HASONEVALUE('Table'[Category1]),
                __SubTotal,
                __GrandTotal
            )
        )

 

 


---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

codjhs
Frequent Visitor

Re: Matrix Measure Total Triple Threat Rock & Roll

Do the formula work between two related tables?

Thanks for your help

TheCAKurtle Helper I
Helper I

Re: Matrix Measure Total Triple Threat Rock & Roll

@Greg_Deckler 

Does this work for 2 fact tables that have 2 different dimensions connected to both? 
So in my case the UWI column in BLOPS Dim is Category 1 and HierarchyCC column in Hierarchy Cost Centers is Category 2. 

 

Thank you for the informative post!! 

 Annotation 2020-04-27 105710.png