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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
shakir99
Frequent Visitor

DAX 'Contain' for columns in different tables with conditional switch

Hi all, 
(A screenshot of the table structure has been included below)

I'm trying to essentially show unique ID values in table 3 (that are retrieved from table 1 and 2) and show the 'latest' phase based on a condition along the lines of 'if table3[id] exists in table1[id], show table1[phase], else if table3[id] exists in table2[id], show table2[phase], else blank()'.

So far, I've done Distinct Union of table1[id] and table2[id] to create table3[id]. Then was planning to do Switch with Contains DAX function to return true or false on whether the table3[id] exists in table1 or table 2 and then show their corresponding phase value  however I saw that contains function can only work within a specified table and not accross tables. 

Any assistance here would be greatly appreciated! (Target state is table 3).

 

shakir99_2-1657257793095.png

 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi,  @shakir99 ,

You could try it.

New = 
var _2= EXCEPT(VALUES('Table2'[ID]),VALUES(Table3[ID]))
var _1=EXCEPT(VALUES(Table1[ID]),UNION(VALUES(Table2[ID]),VALUES(Table3[ID])))
 return UNION(SUMMARIZE(_2,[ID],"Phase","Middle"),SUMMARIZE(_1,[ID],"Phase","Starting"),SUMMARIZE('Table3',[ID],[Phase]))

The final show:

vyalanwumsft_0-1657789514669.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi,  @shakir99 ,

You could try it.

New = 
var _2= EXCEPT(VALUES('Table2'[ID]),VALUES(Table3[ID]))
var _1=EXCEPT(VALUES(Table1[ID]),UNION(VALUES(Table2[ID]),VALUES(Table3[ID])))
 return UNION(SUMMARIZE(_2,[ID],"Phase","Middle"),SUMMARIZE(_1,[ID],"Phase","Starting"),SUMMARIZE('Table3',[ID],[Phase]))

The final show:

vyalanwumsft_0-1657789514669.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-yalanwu-msft
Community Support
Community Support

Hi, @shakir99 ,

Try to create two measure.

Measure = MAX('Table1'[ID]) in SUMMARIZE( INTERSECT('Table1','Table3'),[ID])
Measure 2 = MAX('Table2'[ID]) in SUMMARIZE( INTERSECT('Table2','Table3'),[ID])

the final show:

vyalanwumsft_0-1657617285627.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yalanwu-msft , 
Thanks for your answer however instead of two output measures - is there anyway to just output one table as shown in table 3? That is the desired output. 

amitchandak
Super User
Super User

@shakir99 , Try a new table

Union(Table2, calculatetable(Table1, filter(Table1, not Table[ID] in except(Table2[ID] , Table1[ID]) )))

and when you say "not Table[ID]" in the suggested DAX formula, which table should that be? 1 or 2?

Thanks @amitchandak for the answer however, is there a way I could do this with three tables instead of two? And specify the columns I'd like to be included?

I've posted another question  here finer detailing my query:
https://community.powerbi.com/t5/Desktop/DAX-Contain-for-columns-in-different-tables-with-conditiona... 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.