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 ) )
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
)
)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!
- AlB7 years agoCommunity 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 )