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
anna_zuckers
New Member

How to convert Case function to Dax

I have a formula that I used in Datastudio but I cannot figure out how to convert it to Dax:

 

Formula #1:
CASE
WHEN Word Count> 4 THEN "Long tail"
ELSE "Short tail"
END
 
Formula #2:
CASE
WHEN Avg position >=0 AND Avg position <= 3 THEN "Hyper traffic (1-3) "
WHEN Avg position >3 AND Avg position <= 10 THEN "Traffic (4-10) "
WHEN Avg position >10 AND Avg position <= 20 THEN "Striking Distance (11-20)"
WHEN Avg position > 20 THEN "Did not Rank"
ELSE "No Rank"
END
 
Formula #3: (if query contains "omega", then replace the query to "omega")
CASE
WHEN REGEXP_MATCH(query, '.*omega.*') THEN "Omega"
WHEN REGEXP_MATCH(query, '.*hublot.*') THEN "Hublot"
WHEN REGEXP_MATCH(query, '.*invicta.*') THEN "Invicta"
ELSE "Others"
END
 
I would appreciate any help.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @anna_zuckers ,

Here are the steps you can follow:

Create calculated column.

Formula #1:

Formula #1=
IF(
    [Word Count] >4 ,"Long tail","Short tail")

vyangliumsft_0-1668996559067.png

Formula #2:

Formula #2 =
SWITCH(
    TRUE(),
    [Avg position] >=0&&[Avg position]<=3,"Hyper traffic (1-3)",
    [Avg position] >3&&[Avg position]<=10,"Traffic (4-10)",
    [Avg position] >10&&[Avg position]<=20,"Striking Distance (11-20)",
    [Avg position]>20,"Did not Rank",
    "No Rank")

vyangliumsft_1-1668996559069.png

Formula #3:

Formula #3 =
SWITCH(
    TRUE(),
    CONTAINSSTRING('Table3'[query],".*omega.*")=TRUE(),
SUBSTITUTE(
    [query],".*omega.*","Omega"),
CONTAINSSTRING('Table3'[query],".*hublot.*")=TRUE(),
   SUBSTITUTE(
    [query],".*hublot.*","Hublo"),
CONTAINSSTRING('Table3'[query],".*invicta.*")=TRUE(),
     SUBSTITUTE(
    [query],".*invicta.*","Invicta"),
    "Others")

vyangliumsft_2-1668996559069.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @anna_zuckers ,

Here are the steps you can follow:

Create calculated column.

Formula #1:

Formula #1=
IF(
    [Word Count] >4 ,"Long tail","Short tail")

vyangliumsft_0-1668996559067.png

Formula #2:

Formula #2 =
SWITCH(
    TRUE(),
    [Avg position] >=0&&[Avg position]<=3,"Hyper traffic (1-3)",
    [Avg position] >3&&[Avg position]<=10,"Traffic (4-10)",
    [Avg position] >10&&[Avg position]<=20,"Striking Distance (11-20)",
    [Avg position]>20,"Did not Rank",
    "No Rank")

vyangliumsft_1-1668996559069.png

Formula #3:

Formula #3 =
SWITCH(
    TRUE(),
    CONTAINSSTRING('Table3'[query],".*omega.*")=TRUE(),
SUBSTITUTE(
    [query],".*omega.*","Omega"),
CONTAINSSTRING('Table3'[query],".*hublot.*")=TRUE(),
   SUBSTITUTE(
    [query],".*hublot.*","Hublo"),
CONTAINSSTRING('Table3'[query],".*invicta.*")=TRUE(),
     SUBSTITUTE(
    [query],".*invicta.*","Invicta"),
    "Others")

vyangliumsft_2-1668996559069.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

djurecicK2
Super User
Super User

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