Forum Discussion
Jacob_Li
4 years agoFrequent Visitor
Count total rows within given time range in a given date range
I am working on a measure to get the total headcounts of customers within a given time range. But I need to consider two time ranges: The active period of the customer (StartDate & EndDate) The ti...
- 4 years ago
My code wat not correct. Sorry I'm typing on the phone
try this one
Headcounts = SUMX ( CROSSJOIN ( VALUES ( 'Calendar'[Date] ), VALUES ( 'fact'[StartDate] ) ), CALCULATE ( VAR SelectedDates = VALUES ( 'Calendar'[Date] ) RETURN SUMX ( 'fact', VAR ActiveDates = CALENDAR ( 'fact'[StartDate], 'fact'[EndDate] ) RETURN IF ( COUNTROWS ( INTERSECT ( SelectedDates, ActiveDates ) ) > 0, 1, 0 ) ) ) )
tamerj1
4 years agoCommunity Champion
My code wat not correct. Sorry I'm typing on the phone
try this one
Headcounts =
SUMX (
CROSSJOIN ( VALUES ( 'Calendar'[Date] ), VALUES ( 'fact'[StartDate] ) ),
CALCULATE (
VAR SelectedDates =
VALUES ( 'Calendar'[Date] )
RETURN
SUMX (
'fact',
VAR ActiveDates =
CALENDAR ( 'fact'[StartDate], 'fact'[EndDate] )
RETURN
IF ( COUNTROWS ( INTERSECT ( SelectedDates, ActiveDates ) ) > 0, 1, 0 )
)
)
)Jacob_Li
4 years agoFrequent Visitor
It works! Thank you! Also lots of thanks for all the replies under this post.