Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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!!!
Solved! Go to Solution.
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,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you!!
I see a problem in your measure, the first example is wrong because the total should be 2, and it shows 1.
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,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Your measure is amazing but I cant get it to work, with my real data i get a ID in 2 differents groups :S The example that i'm analyzing right now to check the measure is:
ID | Date (DD/MM/YYYY) | Type |
1 | 06/03/2020 | A |
1 | 02/03/2020 | A |
1 | 19/12/2019 | B |
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
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,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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.
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])
)
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?
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.
@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 )
Unfortunatelly, It doesnt seems to work, every type have value 1 with that measure.
User | Count |
---|---|
102 | |
91 | |
87 | |
79 | |
71 |
User | Count |
---|---|
113 | |
105 | |
101 | |
75 | |
64 |