Forum Discussion
Count first instance in date range
- Anonymous2 years ago
Hi EWBWEBB ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create measures.
Period = var _min= CALCULATE(MIN('Table'[DateKey]),FILTER(ALLSELECTED('Table'),'Table'[ServiceLength_Months]=24 && 'Table'[ID]=MAX('Table'[ID]))) var _Period=CALCULATE(MAX('Table (2)'[Period]),FILTER(ALLSELECTED('Table (2)'),'Table (2)'[DateKey]=_min)) return _PeriodCount = var _table=SUMMARIZE(ALL('Table'),'Table'[ID],"per",[Period]) return COUNTROWS(FILTER(_table,[per] = MAX('Table (2)'[Period])))(3) Then the result is as follows.
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi EWBWEBB ,
According to your description, here are my steps you can follow as a solution.
(1) My test data is the same as yours.
(2) We can create measures.
Period =
var _min= CALCULATE(MIN('Table'[DateKey]),FILTER(ALLSELECTED('Table'),'Table'[ServiceLength_Months]=24 && 'Table'[ID]=MAX('Table'[ID])))
var _Period=CALCULATE(MAX('Table (2)'[Period]),FILTER(ALLSELECTED('Table (2)'),'Table (2)'[DateKey]=_min))
return _PeriodCount =
var _table=SUMMARIZE(ALL('Table'),'Table'[ID],"per",[Period])
return COUNTROWS(FILTER(_table,[per] = MAX('Table (2)'[Period])))
(3) Then the result is as follows.
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- EWBWEBB2 years agoHelper III
Hi Anonymous
This worked perfectly thank you.
Is there a reason that you did this as 2 seperate measures rather than using a Variable for the 'Period' mesaure, or just preference?
Just help inform my thinking next time.
Thanks
Ben