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
walker4545
Frequent Visitor

Calculated Column in DAX to check if values appear in another column, create an array from a table

Hello Power BI gurus, 

 

I need help with the following problem. I need to create a calculated column that evaluates whether a value appears in another column. 

 

Flag

Flag Colours
Red
White
Blue

 

Primary

Primary Colours
Red
Yellow
Blue

 

Primary Colour =
    VAR PrimaryArray = {"Red", "Blue", "Yellow"}
    VAR CheckPrimary = IF('Flag'[Flag Colours] IN PrimaryArray, "Primary Colour", "Not Primary Colour")
    RETURN CheckPrimary
 
The above code is a solution of how I would like the code to work (to calculate a column based on whether a value appears in an array). In the code above I'd like to replace the code in italics to bring in values from the column of another table. However, when attempting to declare the variable PrimaryArray against a column in the Primary Table I cannot access those values. 
 
How can I bring in the values from 'Primary'[Primary Colours] into an array that can be evaluated against to match values?
 
Thanks in advance!
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@walker4545 , Try like

 

Primary Colour =
VAR PrimaryArray = values(Primary[Primary Colours])
VAR CheckPrimary = IF('Flag'[Flag Colours] IN PrimaryArray, "Primary Colour", "Not Primary Colour")
RETURN CheckPrimary

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@walker4545 , Try like

 

Primary Colour =
VAR PrimaryArray = values(Primary[Primary Colours])
VAR CheckPrimary = IF('Flag'[Flag Colours] IN PrimaryArray, "Primary Colour", "Not Primary Colour")
RETURN CheckPrimary

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.