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
UditJ
Helper III
Helper III

Datorama Calculations to Power BI

Is there a way we can replicate the below formula in power bi? 

IF( Site Name == 'DISCOVERY LATIN AMER', 'Discovery Channel Latin Amer',
IF( Media Buy Name contains 'P242V0D', 'Discovery Channel',
IF( Media Buy Name contains 'P2HD113', 'Hulu',
IF( Media Buy Name contains 'P2HKBPJ', 'YouTube Select',
IF( Media Buy Name contains 'P2HD112', 'Hulu',
IF( Media Buy Name contains 'ROKU', 'Roku', TJx-PARTNER [TJx-PARTNER]))))))
1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @UditJ ,

Based on the formula you've provided, it looks like you're attempting to categorize Site Names and Media Buy Names into different groups using a series of nested conditional statements. In Power BI, we can use the `SWITCH` function as an alternative to nested `IF` statements for better readability and maintenance. Here's how you can translate the provided formula:

Channel Name = 
SWITCH(
    TRUE(),
    'YourTable'[Site Name] = "DISCOVERY LATIN AMER", "Discovery Channel Latin Amer",
    CONTAINSSTRING('YourTable'[Media Buy Name], "P242V0D"), "Discovery Channel",
    CONTAINSSTRING('YourTable'[Media Buy Name], "P2HD113"), "Hulu",
    CONTAINSSTRING('YourTable'[Media Buy Name], "P2HKBPJ"), "YouTube Select",
    CONTAINSSTRING('YourTable'[Media Buy Name], "P2HD112"), "Hulu",
    CONTAINSSTRING('YourTable'[Media Buy Name], "ROKU"), "Roku",
    'YourTable'[TJx-PARTNER]
)

Please replace `'YourTable'` with the actual name of your table in Power BI.

 

Here's the step-by-step guide to implement this DAX formula:

1. Open Power BI Desktop and navigate to the Data view.
2. Select the table where you want to create the new calculated column.
3. Go to the Modeling tab and click on "New column".
4. Enter the DAX formula provided above into the formula bar.
5. Press Enter to create the column.

 

This formula uses the `SWITCH` function to evaluate each condition in turn and returns the corresponding channel name when a condition is met. The `CONTAINSSTRING` function is used to check if 'Media Buy Name' contains certain substrings.

 

Best regards,
Community Support Team_Binbin Yu
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

6 REPLIES 6
v-binbinyu-msft
Community Support
Community Support

Hi @UditJ ,

Based on the formula you've provided, it looks like you're attempting to categorize Site Names and Media Buy Names into different groups using a series of nested conditional statements. In Power BI, we can use the `SWITCH` function as an alternative to nested `IF` statements for better readability and maintenance. Here's how you can translate the provided formula:

Channel Name = 
SWITCH(
    TRUE(),
    'YourTable'[Site Name] = "DISCOVERY LATIN AMER", "Discovery Channel Latin Amer",
    CONTAINSSTRING('YourTable'[Media Buy Name], "P242V0D"), "Discovery Channel",
    CONTAINSSTRING('YourTable'[Media Buy Name], "P2HD113"), "Hulu",
    CONTAINSSTRING('YourTable'[Media Buy Name], "P2HKBPJ"), "YouTube Select",
    CONTAINSSTRING('YourTable'[Media Buy Name], "P2HD112"), "Hulu",
    CONTAINSSTRING('YourTable'[Media Buy Name], "ROKU"), "Roku",
    'YourTable'[TJx-PARTNER]
)

Please replace `'YourTable'` with the actual name of your table in Power BI.

 

Here's the step-by-step guide to implement this DAX formula:

1. Open Power BI Desktop and navigate to the Data view.
2. Select the table where you want to create the new calculated column.
3. Go to the Modeling tab and click on "New column".
4. Enter the DAX formula provided above into the formula bar.
5. Press Enter to create the column.

 

This formula uses the `SWITCH` function to evaluate each condition in turn and returns the corresponding channel name when a condition is met. The `CONTAINSSTRING` function is used to check if 'Media Buy Name' contains certain substrings.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

zenisekd
Super User
Super User

Hi, use simple

IF('table'[column name] = "text" , "true statement", "false statement")
https://learn.microsoft.com/en-us/dax/if-function-dax



together with statement CONTAINS(table,column, "statement")
https://learn.microsoft.com/en-us/dax/contains-function-daxhttps://learn.microsoft.com/en-us/dax/con...

Kudos and mark as solution appreciated 🙂

Its not working , could you please demonstrate an example here ?

It is probably not working, because you are tying to do a measure. Do calculated column.

Still not working. The else part isnt working. Highlighted in bold below: 

Test = IF('Reporting.Digital'[CampaignName]="abc","dcf",CONTAINS('Reporting.Digital','Reporting.Digital'[CostMethod],"P242V0D" || "Discovery Channel" || "Hulu" || "Select", 'Reporting.Digital'[CCD_Partner])

You are missing second IF statement
IF('Reporting.Digital'[CampaignName]="abc","dcf",
IF(CONTAINS('Reporting.Digital','Reporting.Digital'[CostMethod],"P242V0D" || "Discovery Channel" || "Hulu" || "Select")'Reporting.Digital'[CCD_Partner])

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.