This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hi Community,
I want to group customer based on years of transaction using SWITCH function.
For example customer A first transaction in 2010 , last transaction in 2020 , so years of transaction is 10.
Like wise for other customers.
Date Diff(measure)
MAX('Table'[Year ])-MIN('Table'[Year ])
Loyalty(New Column)
Loyalty = SWITCH(TRUE(),
[DateDiff]>=0 && [DateDiff]<=2, "BRONZE",
[DateDiff]>=3 && [DateDiff]<=5, "SILVER",
[DateDiff]>=6 && [DateDiff]<=8, "GOLD")
But the column Loyalty when put in a slicer, it doesnt show all groups.
Please check the sample data.
Thank you in advance.
Solved! Go to Solution.
You need to give it a row context to evaluate the DateDiff before you can do the switch, try doing the datediff as a column in the table:
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
You need to give it a row context to evaluate the DateDiff before you can do the switch, try doing the datediff as a column in the table:
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
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 37 | |
| 29 | |
| 29 | |
| 21 | |
| 18 |
| User | Count |
|---|---|
| 68 | |
| 39 | |
| 33 | |
| 24 | |
| 23 |