Forum Discussion
DAX - Exclude values from row total
- 7 years ago
Well, "no success at all" sounds like a bit of an exaggeration...
(N+1)th version. I had posted this already immediately after my latest post as I realised there was an error. But for some reason the post has disappeared. Here it is again
totalamount_openD = VAR income = CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "income" ) VAR costs = CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "costs" ) VAR income_open = CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "income" ) VAR costs_open = CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "costs" ) RETURN IF ( ISFILTERED ( date_table[yearmonth] ); IF ( ISFILTERED ( 'table'[header] ); CALCULATE ( SUM ( 'table'[amount] ) ); income - costs ); IF ( ISFILTERED ( 'table'[header] ); CALCULATE ( SUM ( 'table'[amount_open] ) ); income_open - costs_open ) )
Hi MiKeZZa
Had forgotten about this. Have you tried the following? Let me know
totalamount_open =
VAR income =
CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "income" )
VAR costs =
CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "costs" )
VAR income_open =
CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "income" )
VAR costs_open =
CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "costs" )
RETURN
IF (
MIN ( 'table'[yearmonth] ) <> MAX ( 'table'[yearmonth] );
income_open - costs_open;
income - costs
)Review of the previous. We need to use date_table[yearmonth] rather than table[yearmonth]
totalamount_openB =
VAR income =
CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "income" )
VAR costs =
CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "costs" )
VAR income_open =
CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "income" )
VAR costs_open =
CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "costs" )
RETURN
IF ( ISFILTERED(date_table[yearmonth] );
income - costs;
income_open - costs_open
)
- MiKeZZa7 years ago
Post Patron
How funny. My WiFi was broken so I didn't was able to check for a new post and I've tried to solve it on my own. I came up to the exact same solution like you post now! That works great indeed. Very very very much appriciated!
- MiKeZZa7 years ago
Post Patron
Thank you for your support. We're still getting a bit closer. You've made it a little better, but it's good really good at this moment. See what's marked green (good) and red (not ok):
To make it a little easier for you I've posted the PBIX in a previous post. Here it is again, but now with your latest dax included: https://ufile.io/7iunr
- AlB7 years ago
Community Champion
Nth iteration :smileyvery-happy:
totalamount_openC = VAR income = CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "income" ) VAR costs = CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "costs" ) VAR income_open = CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "income" ) VAR costs_open = CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "costs" ) RETURN IF ( ISFILTERED ( date_table[yearmonth] ); IF ( ISFILTERED ( 'table'[header] ); CALCULATE ( SUM ( 'table'[amount] ) ); income - costs ); income_open - costs_open ) - AlB7 years ago
Community Champion
Well, "no success at all" sounds like a bit of an exaggeration...
(N+1)th version. I had posted this already immediately after my latest post as I realised there was an error. But for some reason the post has disappeared. Here it is again
totalamount_openD = VAR income = CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "income" ) VAR costs = CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "costs" ) VAR income_open = CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "income" ) VAR costs_open = CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "costs" ) RETURN IF ( ISFILTERED ( date_table[yearmonth] ); IF ( ISFILTERED ( 'table'[header] ); CALCULATE ( SUM ( 'table'[amount] ) ); income - costs ); IF ( ISFILTERED ( 'table'[header] ); CALCULATE ( SUM ( 'table'[amount_open] ) ); income_open - costs_open ) ) - AlB7 years ago
Community Champion
Cool :smileyvery-happy:
Here another version, perhaps a bit more maintainable. Matter of preference.
totalamount_openD2 = VAR income = CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "income" ) VAR costs = CALCULATE ( SUM ( 'table'[amount] ); 'table'[header] = "costs" ) VAR income_open = CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "income" ) VAR costs_open = CALCULATE ( SUM ( 'table'[amount_open] ); 'table'[header] = "costs" ) VAR IsGrandTotal = NOT ( ISFILTERED ( date_table[yearmonth] ) )&& NOT ( ISFILTERED ( 'table'[header] ) ) VAR IsRowTotal = NOT ( ISFILTERED ( date_table[yearmonth] ) ) && ISFILTERED ( 'table'[header] ) VAR IsColumnTotal = ISFILTERED ( date_table[yearmonth] ) && NOT ( ISFILTERED ( 'table'[header] ) ) VAR IsNotTotal = ISFILTERED ( date_table[yearmonth] ) && ISFILTERED ( 'table'[header] ) RETURN SWITCH ( TRUE (); IsNotTotal; CALCULATE ( SUM ( 'table'[amount] ) ); IsRowTotal; income - costs; IsColumnTotal; CALCULATE ( SUM ( 'table'[amount_open] ) ); IsGrandTotal; income_open - costs_open )