Forum Discussion
Use Switch with other condition
Hi,
I need help with this issue.
I have a measure to choose the amount according to the month selected
| Color | Value |
| RED | A01 |
| RED | A02 |
| RED | A03 |
| Black | B01 |
| Black | B02 |
| etc |
8 Replies
- MFelixSuper User
Hi gomezc73 ,
Try the following:
SWITCH( true(), SELECTEDVALUE(Slicer_Table[Mes_Largo]) ="January" && SELECTEDVALUE(Categories[Color])="RED" , SUM(F0902[JAN],0))*0.001, SELECTEDVALUE(Slicer_Table[Mes_Largo]) ="February" && SELECTEDVALUE(Categories[Color])="RED", SUM(IF(Categories[Color]="RED",F0902[FEB],0))*0.001, ...- gomezc73Helper V
Thank you for your help, but the command generate an error:
This is the command:
TEst = SWITCH( true(),SELECTEDVALUE(Slicer_Table[Mes_Largo]) ="January" && SELECTEDVALUE(F0902[BU_CAT06])="MAR", SUM(F0902[JAN],0))*0.001,SELECTEDVALUE(Slicer_Table[Mes_Largo]) ="February" && SELECTEDVALUE(F0902[BU_CAT06])="MAR", SUM(F0902[JAN],0))*0.001)This the error Error:"The Synatx for ',' is incorrect. (Dax(Swith(true(),Selecttedvalue...
- MFelixSuper User
Hi gomezc73 ,
My bad did not clean your measure on the SUM it had more than one parameter, should be like this:
TEst = SWITCH ( TRUE (), SELECTEDVALUE ( Slicer_Table[Mes_Largo] ) = "January" && SELECTEDVALUE ( F0902[BU_CAT06] ) = "MAR", SUM ( F0902[JAN] ) * 0.001, SELECTEDVALUE ( Slicer_Table[Mes_Largo] ) = "February" && SELECTEDVALUE ( F0902[BU_CAT06] ) = "MAR", SUM ( F0902[JAN] ) * 0.001 )
- AlexisOlsonSuper User
You should be able to put the color validation outside of the SWITCH.
This might work for you:
Amount_Selected = CALCULATE ( SWITCH ( SELECTEDVALUE ( Slicer_Table[Month] ), "January", SUM ( F0902[JAN] ), "February", SUM ( F0902[FEB] ), "March", SUM ( F0902[MAR] ), "April", SUM ( F0902[APR] ), "May", SUM ( F0902[MAY] ), "June", SUM ( F0902[JUN] ), "July", SUM ( F0902[JUL] ), "August", SUM ( F0902[AUG] ), "September", SUM ( F0902[SEP] ), "October", SUM ( F0902[OCT] ), "November", SUM ( F0902[NOV] ), "December", SUM ( F0902[DEC] ) ) * 0.001, Categories[Color] = "RED" )Or you could try this
Amount_Selected = IF ( SELECTEDVALUE ( Categories[Color] ) = "RED", SWITCH ( SELECTEDVALUE ( Slicer_Table[Month] ), "January", SUM ( F0902[JAN] ), "February", SUM ( F0902[FEB] ), "March", SUM ( F0902[MAR] ), "April", SUM ( F0902[APR] ), "May", SUM ( F0902[MAY] ), "June", SUM ( F0902[JUN] ), "July", SUM ( F0902[JUL] ), "August", SUM ( F0902[AUG] ), "September", SUM ( F0902[SEP] ), "October", SUM ( F0902[OCT] ), "November", SUM ( F0902[NOV] ), "December", SUM ( F0902[DEC] ) ) * 0.001, 0 )The best solution, however, would likely be to avoid this switching entirely by unpivoting your month columns.
- gomezc73Helper V
Thank you for your help, but I can't use it, because in each month I need different validation..
- AlexisOlsonSuper User
In that case, you can just clean up the syntax MFelix suggested
Test = VAR _Mes = SELECTEDVALUE ( Slicer_Table[Mes_Largo] ) VAR _Color = SELECTEDVALUE ( F0902[BU_CAT06] ) RETURN SWITCH ( TRUE (), _Mes = "January" && _Color = "RED", SUM ( F0902[JAN] ) * 0.001, _Mes = "February" && _Color = "BLUE", SUM ( F0902[FEB] ) * 0.001, _Mes = "March" && _Color = "GREEN", SUM ( F0902[MAR] ) * 0.001, ETC )