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
OrionTL
New Member

DAX help with pattern matching between two non-related Tables

Hi,

 

I'm still new to Power BI, so any help is appreciated.

 

I have two tables, one with all raw data for who worked on what product like so (TableA):

Product Person Who Worked on it
ABC-ABBA Bob
DEF-ABBA Steve

 

I have a second table that dictates which of the products are harder to work on (TableB):

Hard Strenous Product
DEF

 

Is there a way to pattern match products from TableA with known hard streneous products from TableB and create a new column for it on TableA? I'm hoping for an "IF" statement where, if it's a hard product, return "HardProduct" and if it's not, then return "NotAHardProduct" within the cell values on the same rows like below:

 

Product Person Who Worked on it Product Type
ABC-ABBA Bob NotAHardProduct
DEF-ABBA Steve HardProduct

 

I know I can do this on M but within "M" I can't refer to the TableB from TableA when creating a custom column within TableA.

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @OrionTL 
Please follow sample file with the solution https://www.dropbox.com/t/wi6ldBAjf4fGEUkX

1.png

TableC = 
ADDCOLUMNS (
    TableA,
    "Product Type", 
        IF (
            ISEMPTY (
                FILTER (
                    TableB,
                    CONTAINSSTRING ( TableA[Product], TableB[Hard Strenous Product] )
                )
            ),
            "Not A Hard Product",
            "Hard Product"
        )
)

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @OrionTL 
Please follow sample file with the solution https://www.dropbox.com/t/wi6ldBAjf4fGEUkX

1.png

TableC = 
ADDCOLUMNS (
    TableA,
    "Product Type", 
        IF (
            ISEMPTY (
                FILTER (
                    TableB,
                    CONTAINSSTRING ( TableA[Product], TableB[Hard Strenous Product] )
                )
            ),
            "Not A Hard Product",
            "Hard Product"
        )
)

Thank you @tamerj1 !

I was hoping to make it upon the already existing tableA but creating a new one is fine too.

 

I appreciate your help!

@OrionTL 
Ofcourse you can. Actually it is the same code of the column created inside ADDCOLUMNS 

1.png

ProductType = 
IF (
    ISEMPTY (
        FILTER (
            TableB,
            CONTAINSSTRING ( TableA[Product], TableB[Hard Strenous Product] )
        )
    ),
    "Not A Hard Product",
    "Hard Product"
)
tamerj1
Super User
Super User

Hi @OrionTL 

that would be much easier using dax calculated table or a measure in your power bi report. Would you consider that?

I have tried using a DAX calculatedtable like so

HType = 
VAR Matches =
CALCULATETABLE
(
    GENERATE('HardProducts',
    FILTER
    (
        Product_BuyOff,
        SEARCH
        (
            [Assemblies],
            [Part Number],
            1,
            0
        )
        >0)
    )
)
RETURN
    CONCATENATEX(
        Matches,
        "LH",",")


but I just get blank cells for the non-matching ones and "LH" for the matching ones. I can't figure out how to modify that code to make the blanks return another value when it's not matching.

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