Forum Discussion
Switch with multiple conditions from 2 tables
- 3 years ago
Hi cjcj ,
If you can't use the RELATED function, you can modify the formula like this:
TEST = VAR _T = ADDCOLUMNS ( 'table1', "temp", MAXX ( FILTER ( 'table2', 'table2'[ID] = EARLIER ( table1[ID] ) ), 'table2'[temp] ) ) RETURN SUMX ( _T, SWITCH ( TRUE (), [color] = "RED" && [temp] = "WARM", 2345, [color] = "BLUE" && [temp] = "HOT", 1345 ) )It can also get the correct result.
I attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi cjcj ,
According to your description, I create a sample.
table1:
table2:
The two tables are related with the ID column. Here's my solution.
Create a measure.
TEST =
VAR _T =
ADDCOLUMNS ( 'table1', "temp", RELATED ( 'table2'[temp] ) )
RETURN
SUMX (
_T,
SWITCH (
TRUE (),
[color] = "RED"
&& [temp] = "WARM", 2345,
[color] = "BLUE"
&& [temp] = "HOT", 1345
)
)
As you can see, only the ID1 and ID2 match the condition. Get the correct result.
I attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yanjiang-msft Thank you for your response! I am getting an error saying the Parameter is not the correct type. Since I am using DirectQuery, I am not sure how or if the 2 tables are related.
ADDCOLUMNS ( 'table1', "temp", RELATED ( 'table2'[temp] ) )
- v-yanjiang-msft3 years ago
Community Support
Hi cjcj ,
If you can't use the RELATED function, you can modify the formula like this:
TEST = VAR _T = ADDCOLUMNS ( 'table1', "temp", MAXX ( FILTER ( 'table2', 'table2'[ID] = EARLIER ( table1[ID] ) ), 'table2'[temp] ) ) RETURN SUMX ( _T, SWITCH ( TRUE (), [color] = "RED" && [temp] = "WARM", 2345, [color] = "BLUE" && [temp] = "HOT", 1345 ) )It can also get the correct result.
I attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- cjcj3 years ago
Helper I
v-yanjiang-msft that worked great! thank you