Forum Discussion
Last transaction dynamically
Hello!
I'm trying to find the lastest transaction in a dynamic period, I have checked another posts in the forum but they doesnt work.
I have tried everything and I can get them but the dynamic calculation is so slow like 2 min aprox.
I'll let here a example of my problem:
Data:
| ID | Date (DD/MM/YYYY) | Type |
| 1 | 10/10/2020 | A |
| 1 | 08/12/2020 | B |
| 2 | 12/11/2020 | A |
Results expected:
**First example (Filter: 01/01/2019-31/11/2020)
| Type | Count |
| A | 2 |
| Total | 2 |
**Second example (Filter: 01/01/2019-31/12/2020)
| Type | Count |
| A | 1 |
| B | 1 |
| Total | 2 |
If someone can help, i'll be really happy!
Thank you!!!
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.
13 Replies
- amitchandakSuper User
Anonymous , Try a measure like
Status =
VAR __id = MAX ('Table'[ID] )
VAR __date = CALCULATE ( MAX('Table'[Date] ), ALLSELECTED ('Table' ), 'Table'[ID] = __id )
CALCULATE ( count('Table'[Status] ), VALUES ('Table'[ID] ),'Table'[ID] = __id,'Table'[Date] = __date )- AnonymousNot applicable
Unfortunatelly, It doesnt seems to work, every type have value 1 with that measure.
- ArentirResolver III
Hi Anonymous ,
I didn't quite understand the result expected example part. From the problem description I understand you want to show :
In case all dates are selected
ID Date (DD/MM/YYYY) Type 1 08/12/2020 B In calse 01/01/2020 to 30/11/2020 is selected
ID Date (DD/MM/YYYY) Type 2 12/11/2020 A is that correct?
- AnonymousNot applicable
I want to know the count of each type for the lastest transaction of a certain period of time, the period will be a slicer, so it needs to be dynamic.
In case all date are selected the lastest transaction for each ID are the ones that you said.
- v-kkf-msftCommunity Support
Hi Anonymous ,
Try the following formula:
Measure = var MaxDate = CALCULATE( MAX('Table'[Date]), ALLSELECTED('Table'), GROUPBY('Table','Table'[ID]) ) return CALCULATE( COUNT('Table'[Type]), GROUPBY( FILTER( ALLSELECTED('Table'), 'Table'[Date] = MaxDate ), 'Table'[Type] ) )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.
- AnonymousNot applicable
Thank you!!
I see a problem in your measure, the first example is wrong because the total should be 2, and it shows 1.
- v-kkf-msftCommunity Support
Hi Anonymous ,
Try the following formula:
Measure = var MaxDate = CALCULATE( MAX('Table'[Date]), ALLSELECTED('Table'), GROUPBY('Table','Table'[ID]) ) var result = CALCULATE( COUNT('Table'[Type]), GROUPBY( FILTER( ALLSELECTED('Table'), 'Table'[Date] = MaxDate ), '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.