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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
josevaras
Employee
Employee

I think I can use Switch....

Hello all - as always, thank you very much - in advance. 

 

In a nutshell I would like to know if I there is a function in DAX that works the same as a the below Excel formula. 

 

=
IF(ISNUMBER(SEARCH("AMASale",[@[Partners]])),"Amazon",
IF(ISNUMBER(SEARCH("CstcSale",[@[Partners]])),"Costco",[@[Non-Partners]]))))))

 

What the formula is doing is looking at the Partners column and for each cell (row) it is returning "Amazon" if within the string it says AMASale and "Costco" if within the string it says CstcSale. If nothing is found (meaning no AMASale or CstcSale) then it will return what ever is listed in the Non-Partners cell. 

If you are all familiar with Excel, apologies for the explanation.

Is there a way for me to do something similar in PBI Desktop? I am thinking within PQE, add a new column and reference the columns I need but I am not sure on the correct DAX to use. Thanks

 

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

PQE?     Is this Power Query?

 

If so, add a column with this code

if Text.Contains([Column1], "AMASale") then "Amazon" else if Text.Contains([Column1], "CstcSale") then "Costco" else [theothercolumn]

 

View solution in original post

2 REPLIES 2
HotChilli
Super User
Super User

PQE?     Is this Power Query?

 

If so, add a column with this code

if Text.Contains([Column1], "AMASale") then "Amazon" else if Text.Contains([Column1], "CstcSale") then "Costco" else [theothercolumn]

 

Anonymous
Not applicable

You can achieve same in dax using stringcontains function and switch statement.
New column=Switch(true(), stringcontains (table[col],"string1"), "expected output",
stringcontains (table[col],"string2"), "outut",table[expectedColumn])

But my recommendation is create it in power query for the better performance.


Thanks
Pravin

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors