Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have a column with text values such as:
16101X
16102X
16103X
16C01A
16C02A
16C03A
etc.
I want to add a calculated column that groups these using a switch statement like so:
SWITCH(
TRUE(),
[value] >= "16101X" && [value] <= "16103X", "A",
[value] >= "16C01A" && [value] <= "16C03A", "B",
"OTHER"
)
However, the greater/less than operator does not work on text, obviously.
Any ideas? Thanks in advance! I will give kudos and mark your response as the solution if it works.
Solved! Go to Solution.
@kpost My take is the opposite of what you said, if you can do it at the backend, it is always advisable to do it there then doing it in Power BI. I'm sure if you have CASE logic in SQL, you can easily translate that into DAX. Not sure if I can be of further help.
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@kpost My take is the opposite of what you said, if you can do it at the backend, it is always advisable to do it there then doing it in Power BI. I'm sure if you have CASE logic in SQL, you can easily translate that into DAX. Not sure if I can be of further help.
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
I absolutely can do it in SQL, as SQL allows comparing text using comparison operators like <= etc.
Maybe this is the best solution after all. Thanks.
Unfortunately there is no consistent pattern.
It is a massive sheet containing 10s of thousands of codes that must be grouped somewhat arbitrarily, but in the vast majority of cases they are being grouped like this, where codes that are alphabetically next to each other are grouped into the same groups.
I could do it on the back end using SQL (I'm pulling this from a database originally) and just add a column with a bunch of CASE statements without much trouble, but I'd strongly prefer to do it in Power BI.
@kpost as you said text will not work in the above case but what is the logic for grouping, maybe that can help to derive the solution.
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
User | Count |
---|---|
72 | |
66 | |
34 | |
25 | |
22 |
User | Count |
---|---|
96 | |
94 | |
58 | |
45 | |
42 |