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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
karma
Advocate II
Advocate II

categorical data scenario dax query

Hi folks,

I hope you all are doing well and at your best health.


I have a doubt in a scenario based question. I have a categorical data - with 8 different categories. I want to flag these categories as 1,2,...8.
I was thinking about using if condition but I need to write if condition 8 times. Is there a better way of doing it? Thanks in advance! 

2 ACCEPTED SOLUTIONS
truptis
Community Champion
Community Champion

Hi @karma ,

If you don't wish to go with IF condition then you can try SWITCH() in dax. Below is the link for the same.

https://docs.microsoft.com/en-us/dax/switch-function-dax

 

Please hit the thumbs up & mark it as a solution if this helps you. Thanks.

View solution in original post

truptis
Community Champion
Community Champion

@karma -> try this:

Result = SWITCH([COLUMNNAME], "A", 1, "B", 2, "C",3, "D",4,"E",5,"F",6,"G",7,"H",8, 0)

 

Please hit the thumbs up & mark it as a solution if it helps you. Thanks.

View solution in original post

5 REPLIES 5
karma
Advocate II
Advocate II

 Thanks @truptis ! it worked! 

truptis
Community Champion
Community Champion

Hi @karma ,

If you don't wish to go with IF condition then you can try SWITCH() in dax. Below is the link for the same.

https://docs.microsoft.com/en-us/dax/switch-function-dax

 

Please hit the thumbs up & mark it as a solution if this helps you. Thanks.

Thanks for your quick response @truptis . Is it possible for you to help me writing the measure? 
i have a field -Category and within that field i have A, B, C, D, E, F,G & H and I want to number them as 1,2...8 and if no letter is there then mark it as 0.

simply follow this :

MEASURE = SWITCH(TRUE(),
A=?, 1,
B=?, 2,

C=?, 3,

D=?, 4,

BLANK()

)

 

OR
MEASURE =
IF(A),1,
IF(B),2,

IF(C),3,

IF(D),4,
BLANK()
))))

truptis
Community Champion
Community Champion

@karma -> try this:

Result = SWITCH([COLUMNNAME], "A", 1, "B", 2, "C",3, "D",4,"E",5,"F",6,"G",7,"H",8, 0)

 

Please hit the thumbs up & mark it as a solution if it helps you. Thanks.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors