Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.