Forum Discussion

EnrichedUser's avatar
EnrichedUser
Icon for Helper III rankHelper III
4 years ago
Solved

Incorrect Totals - Matrix

Good Day!   I think I have a rather complex situation and would greatly apprecaite some help.    Specifically, I am not able to correctly determine the row, column or grand totals at the 'Site' l...
  • EnrichedUser's avatar
    4 years ago
    Customer Inflation with Fixed Totals = 
    VAR vTable = 
    ADDCOLUMNS(
        SUMMARIZE('Invoice History',
            'Date'[Fiscal Year Number],
            'Date'[Month],
            'Invoice History'[Site],
            'Invoice History'[Item Number]
        ),
        "@inflation", [Customer Inflation]
    )
    VAR TotalInflation =
        SWITCH(
            TRUE(),
            HASONEVALUE('Date'[Month]) && HASONEVALUE('Invoice History'[Item Number]),
                [Customer Inflation],   // Base data
            HASONEVALUE('Date'[Month]),  
                CALCULATE(
                    SUMX( vTable,
                    [@inflation]
                    )
                ),                                                                      // column totals,
            HASONEVALUE('Invoice History'[Item Number]),                                // row totals
                CALCULATE(
                    SUMX(
                        vTable,
                        [@inflation]
                    ),
                    VALUES('Date'[Month])
                ),                                                                      // grand total
            SUMX(
                vTable,
                [@inflation]
            )
        )
    RETURN
        TotalInflation

    Working solution