Forum Discussion
Anonymous
3 years agoNot applicable
Sum the line items based on condition
Hi everyone, I'm trying to write a formula for the conditions below. Someone please help me write a code for the condition. Here for the number of days, I'm want to calculate no of days based...
- 3 years ago
Try
Total Days = SUMX ( 'Table', IF ( 'Table'[Hours] > 0, 1 ) )
johnt75
3 years agoSuper User
Try
Total Days =
SUMX ( 'Table', IF ( 'Table'[Hours] > 0, 1 ) )
AlexisOlson
3 years agoSuper User
This solution works fine but, in general, DAX is more efficient with filtering operations than evaluating IF on every iteration. A bit more detail here: https://blog.enterprisedna.co/iterators-and-context-transitions-in-dax-queries/
You could rewrite this using filtering like this:
SUMX ( FILTER ( 'Table', 'Table'[Hours] > 0 ), 1 )
Or even something like this:
CALCULATE ( COUNTROWS ( 'Table' ), 'Table'[Hours] > 0 )