Forum Discussion

UditJ's avatar
UditJ
Icon for Helper III rankHelper III
2 years ago
Solved

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]))))))
  • Anonymous's avatar
    Anonymous
    2 years ago

    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.

6 Replies

    • UditJ's avatar
      UditJ
      Icon for Helper III rankHelper III

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

      • zenisekd's avatar
        zenisekd
        Icon for Super User rankSuper User
        It is probably not working, because you are tying to do a measure. Do calculated column.
  • Anonymous's avatar
    Anonymous
    Not applicable

    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.