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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
sk007
Regular Visitor

Switch statement for columns from different tables

I have two tables like this: 

Table1

sk007_0-1654277344349.png 

Table2

sk007_1-1654277381367.png

 

I want to create a new column in either of the table with condition like this: 

If pay is Table1[pay] = "A" or Table1[pay] = "B" then, NewDate = Table2[n_date]

If pay is Table1[pay] = "C" or Table1[pay] = "D" then, NewDate = Table2[p_date]

sk007_2-1654277569820.png

 

How can i do this using Switch or other DAX query?

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sk007 ,

 

If you want to calculate between Table1 and Table2, there should be a keycolumn to relate two tables. Or we couldn't determind which row each pay will be related to.

I agree with amitchandak, you can refer to his video to add an [Index] column in two tables in Power Query Editor. Please make sure you have sort two tables as you want before you add an [Index] column.

Relationship:

RicoZhou_0-1654573448556.png

Then your calculation will be easy.

Calculated Column:

NewDate =
SWITCH (
    TRUE (),
    Table1[pay] IN { "A", "B" }, RELATED ( Table2[n_date] ),
    Table1[pay] IN { "C", "D" }, RELATED ( Table2[p_date] )
)

 Result is as below.

RicoZhou_1-1654573584955.png

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @sk007 ,

 

If you want to calculate between Table1 and Table2, there should be a keycolumn to relate two tables. Or we couldn't determind which row each pay will be related to.

I agree with amitchandak, you can refer to his video to add an [Index] column in two tables in Power Query Editor. Please make sure you have sort two tables as you want before you add an [Index] column.

Relationship:

RicoZhou_0-1654573448556.png

Then your calculation will be easy.

Calculated Column:

NewDate =
SWITCH (
    TRUE (),
    Table1[pay] IN { "A", "B" }, RELATED ( Table2[n_date] ),
    Table1[pay] IN { "C", "D" }, RELATED ( Table2[p_date] )
)

 Result is as below.

RicoZhou_1-1654573584955.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@sk007 , How will the row will get decided? both of them need have pay or add an index column in the power query

 

Power Query- Index Column: https://youtu.be/NS4esnCDqVw

 

 

Then have a column in Table on

 

COlumn =

Var _1 = maxx(filter(Table2, Table1[pay] =Table2[Pay]) ,[n_date]) // use index in place of pay if needed

Var _2 = maxx(filter(Table2, Table1[pay] =Table2[Pay]) ,[p_date])// use index in place of pay if needed

return

if([Pay] in {"A", "B"} , _1,_2)

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.