Forum Discussion
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 Date | Extended Cost | Quantity | Site_Item_Key |
| 3/13/2023 | 9.7 | 100 | SFA250 |
| 3/31/2023 | 9.7 | 100 | SFA250 |
| 6/26/2023 | 9.327 | 100 | SFA250 |
| 1/12/2023 | 325.56 | 6 | SFA479 |
| 4/3/2023 | 927.1 | 10 | SFA479 |
| 5/11/2023 | 927.1 | 10 | SFA479 |
| 6/22/2023 | 8045.9 | 305 | SFA479 |
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)]
5 Replies
- Ashish_Mathur
Super User
Hi,
Your expected result is not clear. For a sample dataset, show the expected result.
- EnrichedUser
Helper 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!
- Ashish_Mathur
Super User
Hi,
Share the download link of the PBI file.
- EnrichedUser
Helper III
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