Forum Discussion

EnrichedUser's avatar
EnrichedUser
Icon for Helper III rankHelper III
3 years ago

Incorrect Column Total: Row/Grand Totals are good

Hi All,

I have found my most bizzare case in Power BI yet and would love some help. My measure is returning correctly for each row, but fails when calculating the column totals. For sake of debugging my dax, I have replaced my intented measure with a value of 1.

 

What I am seeing is that the column totals are only calculating when there is data in the 'receipts' table. Jan has a one receipt as is returning 1, June has receipts for both keys and is returning two. July to Dec have no receipts and are returning blank. 

 

The expected outcome will correctly sum the column totals (all would be 2 in this example).

 

 

 My model is very simple. It is comprised of a the 'Receipts' table and a fairly standard date table. 

 

Receipts sample:

Eff DateExtended CostQuantitySite_Item_Key
3/13/20239.7100SFA250
3/31/20239.7100SFA250
6/26/20239.327100SFA250
1/12/2023325.566SFA479
4/3/2023927.110SFA479
5/11/2023927.110SFA479
6/22/20238045.9305SFA479

Main sections would be the vTable and column totals

 

 

 

Monthly Inflation (TEST3) = 
VAR SelMo = SELECTEDVALUE( 'Date'[Year Month] )
VAR SelKey = SELECTEDVALUE( Receipts[Site_Item_Key] )
VAR vTable = 
ADDCOLUMNS(
    SUMMARIZE(
        GENERATE(
            VALUES(Receipts[Site_Item_Key]),
            VALUES('Date'[Year Month])
        ),
        Receipts[Site_Item_Key],
        'Date'[Year Month]
        ),
    "@Monthly Inflation", 1 -- PLACEHOLDER/Test
    )
Var Result = 
SWITCH(
    TRUE(),

    ISINSCOPE( Receipts[Site_Item_Key] )
        && ISINSCOPE( 'Date'[Year Month] ), 1, // BASE DATA ROWS

    ISINSCOPE( 'Date'[Year Month] ), // COLUMN TOTALS - HELP
        CALCULATE(
            SUMX( 
                vTable, 
                1 
            ),
            VALUES( Receipts[Site_Item_Key] )
        ),       
    ISINSCOPE( Receipts[Site_Item_Key] ), // ROW TOTALS
        CALCULATE( 
            SUMX( 
                vTable, 
                [@Monthly Inflation] 
            ),
            VALUES( 'Date'[Year Month]  )

        ), // GRAND TOTAL
        SUMX(
            vTable,
            [@Monthly Inflation]
        )
    )
RETURN
Result

 

 

The "1" place holder will be replaced with a measure [Monthly Inflation (R)]

 amitchandak 

5 Replies

  • Hi,

    Your expected result is not clear.  For a sample dataset, show the expected result.

    • EnrichedUser's avatar
      EnrichedUser
      Icon for Helper III rankHelper III

      Hi, thank you for taking time to review. I just updated the post so that the picture used the same data as the sample and added more detail.

       

      Please let me know if there is any more clarify I can provide. Thanks again!

  • Monthly Inflation (Test4) = 
    VAR SelMo = SELECTEDVALUE('Date'[Year Month])
    VAR SelKey = SELECTEDVALUE(Receipts[Site_Item_Key])
    VAR vTable =
        ADDCOLUMNS(
            SUMMARIZE(
                GENERATE(
                    VALUES(Receipts[Site_Item_Key]),
                    VALUES('Date'[Year Month])
                ),
                Receipts[Site_Item_Key],
                'Date'[Year Month]
            ),
            "@Monthly Inflation", 1 // Placeholder
        )
    VAR RowTotal =
        CALCULATE(
            SUMX(
                vTable,
                [@Monthly Inflation]
            ),
            ALL('Date'[Year Month])
        )
    VAR ColumnTotal = // HELP
        CALCULATE(
            SUMX(
                vTable,
                [@Monthly Inflation] ),
            ALL(Receipts[Site_Item_Key]),
            VALUES('Date'[Year Month])
        )
    VAR GrandTotal =
        SUMX(
            vTable,
            [@Monthly Inflation]
        )
    RETURN
        IF(
            ISINSCOPE(Receipts[Site_Item_Key]) && ISINSCOPE('Date'[Year Month]),
            1, // Placeholder
            IF(
                ISINSCOPE('Date'[Year Month]),
                ColumnTotal,
                IF(
                    ISINSCOPE(Receipts[Site_Item_Key]),
                    RowTotal,
                    GrandTotal
                )
            )
        )

    Newest Revision