Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have a table similar to the below where i am trying to calculate for each row where activity type is "Order" the earliest (based on Date) Activity Type for each customer id.
Any ideas on how i could proceed?
Activity Id | Activity Type | Date | Customer Id | Desired result |
1 | Call | 1/1/2020 | 1 | n/a |
2 | Order | 3/1/2020 | 1 | Call |
3 | 2/1/2020 | 2 | n/a | |
4 | Call | 4/1/2020 | 2 | n/a |
5 | Order | 6/1/2020 | 2 | Call |
6 | 4/1/2020 | 3 | n/a | |
7 | Order | 6/1/2020 | 3 |
Solved! Go to Solution.
Of course, that makes perfect sense.
In that case the DAX is even simpler:
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
@Anonymous , Both as new columns
Last Activity = maxx(filter(Table, [Customer Id]=earlier([Customer Id]) && [Activity ]<earlier([Activity ])),[Activity ])
Last Activity Type = maxx(filter(Table, [Customer Id]=earlier([Customer Id]) && [Activity ]=earlier([Last Activity])),[Activity Type])
With slight change from @amitchandak this is the final dax.
Two columns
Last Activity Date = maxx(filter(Table, [Customer Id]=earlier([Customer Id]) && [Activity Date]<earlier([Activity Date])),[Activity Date]) #This gives you the closest actvity date to each activity
Last Activity Type = maxx(filter(Table, [Customer Id]=earlier([Customer Id]) && [Activity ]=earlier([Last Activity])),[Activity Type]) #This gives you the closest activity type to each order
It worked, used in the first column Date instead of activity, FILTER(... && Date<earlier(Date),Date).
Thank you so much.
@Anonymous This should do the trick:
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
sorry that was misleading, n/a because i need to calculate the above only when the activity type is "order" since i want to establish which type of activity has caused the order.
Of course, that makes perfect sense.
In that case the DAX is even simpler:
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
First of all thank you for supporting and trying to help, this is definitely much appreciated.
I will keep as solved anyway your second answer becuase it might help people that want to see what is the first/min date or activity.
there was two problems in my case,
I was sort of looking for the max preceeding the order activity
Also it was taking the absolute min and if more than one order per customer it would only take one value.
Thanks anyway i wish you a great day.
F.
Your original post said 'earliest' so I took that to mean the min(), but glad you got it working.
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
https://sites.google.com/site/allisonkennedycv
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
81 | |
66 | |
58 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |