Forum Discussion
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:
CASE
- Anonymous3 years ago
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")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")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")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
2 Replies
- djurecicSuper User
Hi anna_zuckers ,
Please consider using a SWITCH statement to mimic this behavior in DAX
https://learn.microsoft.com/en-us/dax/switch-function-dax
https://p3adaptive.com/2015/03/the-diabolical-genius-of-switch-true/
- AnonymousNot 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")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")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")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