Forum Discussion
Count and filter between two dates
- 5 years ago
Hi, nicole1995
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Current Subscription:
Expired Subscription:
You may create a measure as below.
Result = var t = ADDCOLUMNS( ALL('Current Subscriptions'), "Result", var _startdate = [StartDate] var _date = EOMONTH(_startdate,-1) var _d = DATE(YEAR(_date),MONTH(_date),DAY(_startdate)) return COUNTROWS( FILTER( ALL('Expired Subscriptions'), [MemberID]=EARLIER('Current Subscriptions'[MemberID])&& [EndDate]>=_d&& [EndDate]<=_startdate-1 ) ) ) var _result = SUMX( SUMMARIZE( 'Current Subscriptions', 'Current Subscriptions'[Type], 'Current Subscriptions'[StartDate].[Month], "Re", SUMX( FILTER( t, [Type]=SELECTEDVALUE('Current Subscriptions'[Type])&& 'Current Subscriptions'[StartDate].[Month]=EARLIER('Current Subscriptions'[StartDate].[Month]) ), [Result] ) ), [Re] ) return IF( ISBLANK(_result), 0, _result )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
nicole1995 - DATEADD will return a column of values. Try:
CALCULATE(
COUNTROWS('CurrentSubscriptions'),
FILTER(
'ExpiredSubscriptions',
'ExpiredSubscriptions'[EndDate] <= ('CurrentSubscriptions'[StartDate].[Date] -1) * 1.
&& 'ExpiredSubscriptions'[EndDate] >= EOMONT('CurrentSubscriptions'[StartDate].[Date],-1)
))
- nicole19955 years agoFrequent Visitor
Hi Greg_Deckler
Thanks for your quick reply.
I have tried the query but it won't let me filter between two tables. Is there something I'm missing ?
- Greg_Deckler5 years agoCommunity Champion
nicole1995 - Oh, you probably need an aggregator around a column reference (MAX, MIN, etc.) or MAXX(RELATEDTABLE(...)...)