Forum Discussion
Switch statement for columns from different tables
- Anonymous4 years ago
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:
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.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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:
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.
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.