Forum Discussion

adityavighne's avatar
adityavighne
Icon for Continued Contributor rankContinued Contributor
1 year ago
Solved

Search and map values if contains from another table

Hi I need help regarding   I have   table 1   Category Type Category 1 Type1 Category 2 Type2 Category 3 Type3   table 2 Country Type  USA Type 1, Type 3 ...
  • bhanu_gautam's avatar
    1 year ago

    adityavighne 

    Load the Data: Load both Table 1 and Table 2 into Power BI.

     

    Ensure there is a relationship between the two tables based on the Type column. If the Type column in Table 2 contains multiple types separated by commas, you will need to split these into separate rows.

     

    Split the Type Column in Table 2:

    Go to the Power Query Editor.
    Select the Type column in Table 2.
    Use the "Split Column" feature to split by delimiter (comma in this case).
    This will create multiple columns for each type. You can then unpivot these columns to create a row for each type.


    Unpivot the Split Columns:

    Select the newly created columns from the split operation.
    Use the "Unpivot Columns" feature to transform these columns into rows.


    Create a Filter:

    Create a slicer visual in Power BI and use the Category column from Table 1.
    This slicer will allow you to filter based on the selected category.

     

    Create a measure or calculated column to filter Table 2 based on the selected category from Table 1.

    DAX
    SelectedCountries =
    VAR SelectedCategory = SELECTEDVALUE('Table 1'[Category])
    VAR SelectedType = CALCULATE(VALUES('Table 1'[Type]), 'Table 1'[Category] = SelectedCategory)
    RETURN
    CALCULATETABLE(
    VALUES('Table 2'[Country]),
    FILTER(
    'Table 2',
    CONTAINSSTRING('Table 2'[Type], SelectedType)
    )
    )