Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
kpost
Super User
Super User

Text value alphabetically between two other values, resolved as TRUE/FALSE

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.

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@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.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@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.

kpost
Super User
Super User

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.

parry2k
Super User
Super User

@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.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.