Forum Discussion
Sum values only with a threshold based on header level
- 2 years ago
Hi Penguin12 ,
In this case, to reuse this logic in multiple measures in a performatic way, my suggestion is to create a calculated column in the original table to have the total for each header. For this you can use the same logic in the previous reply:
NewColumn = CALCULATE ( SUM ( 'Table'[Amount] ), ALLEXCEPT ( 'Table', 'Table'[OrderHeader] ) )
Then you can use this column to filter as needed using CALCULATE/FILTER.
Otherwise, just use the variable below in each measure to calculate the table on the fly (the is no problem with this approach).VAR _Table_Total_Header = ADDCOLUMNS ( 'Table', "Header_Total", CALCULATE ( SUM ( 'Table'[Amount] ), ALLEXCEPT ( 'Table', 'Table'[OrderHeader] ) ) )Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!
Best regards,
Joao Ribeiro
joaoribeiro thank you very much for reply! But is there a way to rather have it in two measures so I can use the second one for example in different contexts in tables instead of creating a new table? I have been struggeling with this and was not able to rewrite it
Hi Penguin12 ,
In this case, to reuse this logic in multiple measures in a performatic way, my suggestion is to create a calculated column in the original table to have the total for each header. For this you can use the same logic in the previous reply:
NewColumn =
CALCULATE (
SUM ( 'Table'[Amount] ),
ALLEXCEPT ( 'Table', 'Table'[OrderHeader] )
)
Then you can use this column to filter as needed using CALCULATE/FILTER.
Otherwise, just use the variable below in each measure to calculate the table on the fly (the is no problem with this approach).
VAR _Table_Total_Header =
ADDCOLUMNS (
'Table',
"Header_Total",
CALCULATE (
SUM ( 'Table'[Amount] ),
ALLEXCEPT ( 'Table', 'Table'[OrderHeader] )
)
)
Hope this answer solves your problem!
If you need any additional help please @ me in your reply.
If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
Thanks!
Best regards,
Joao Ribeiro