Forum Discussion
Last transaction dynamically
- 5 years ago
Hi Anonymous ,
Try the following formula:
Max_Date = CALCULATE( MAX('Table'[Date]), ALLSELECTED('Table'), GROUPBY('Table','Table'[ID]) )Measure = var result = CALCULATE( COUNT('Table'[ID]), FILTER( ALLSELECTED('Table'), 'Table'[Date] = [Max_Date] && 'Table'[Type] = MAX('Table'[Type]) ) ) return IF( HASONEFILTER('Table'[Type]), result, DISTINCTCOUNT('Table'[ID]) )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
WinnizIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
Could you describe in detail what went wrong? What I understand is that there is only one latest status for each ID during the selected period. Therefore, the Total part is the total number of id in the time period.
Best Regards,
Winniz
Exactly, you described it perfectly. But with your measure i'm getting 2 transactions for a ID in the selected period
- v-kkf-msft5 years agoCommunity Support
Hi Anonymous ,
Try the following formula:
Max_Date = CALCULATE( MAX('Table'[Date]), ALLSELECTED('Table'), GROUPBY('Table','Table'[ID]) )Measure = var result = CALCULATE( COUNT('Table'[ID]), FILTER( ALLSELECTED('Table'), 'Table'[Date] = [Max_Date] && 'Table'[Type] = MAX('Table'[Type]) ) ) return IF( HASONEFILTER('Table'[Type]), result, DISTINCTCOUNT('Table'[ID]) )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
WinnizIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous5 years agoNot applicable
This measures works perfectly fine!! I just got another problem, i have got a subtype for each type and i cannot count them correctly if i add the subtype to the measure.
- Anonymous5 years agoNot applicable
I got it!
Measure = var resultType = CALCULATE( COUNT('Table'[ID]), FILTER( ALLSELECTED('Table'), 'Table'[Date] = [Max_Date] && 'Table'[Type] = MAX('Table'[Type]) ) ) var resultSubType = CALCULATE( COUNT('Table'[ID]), FILTER( ALLSELECTED('Table'), 'Table'[Date] = [Max_Date] && 'Table'[Type] = MAX('Table'[Type]) && 'Table'[SubType] = MAX('Table'[SubType]) ) ) return IF( HASONEFILTER('Table'[Type]), IF( HASONEFILTER('Table'[SubType]), resultSubType, resultType ), DISTINCTCOUNT('Table'[ID]) )