Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hey, trying to do a multiple condition Switch True Statement. In the beginning of the contract a client had a product that sits in P1, then during their contract period they either kept the same product (retained), upgraded, downgraded, or blank (cancelled). So I have logic on this becuase muliple products fall under the multiple business units. So i made variables for each column of products (different table) and labeled the variables as the business unit name ( a column/variable for every business unit). So when my switch statement would go and look for that variable and in that underlying column to see if its an upgrade, downgrade, ect. I then got "multiple values when one was expected error" and added 2 IF and HASONEVALUE formulas but now my output is blank, any help?
Solved! Go to Solution.
@Anonymous This looks like a reasonable interpretation for how to handle multiple values. However, the naked P1, P2 column references will probably still cause problems.
This is what my version would look like using this logic:
Migration Status =
VAR RB = VALUES ( 'Consolidated Sheet'[RB] )
VAR GTP = VALUES ( 'Consolidated Sheet'[GTP] )
VAR GBS = VALUES ( 'Consolidated Sheet'[GBS] )
VAR ITL = VALUES ( 'Consolidated Sheet'[ITL - EXP non premium - EITL - Non premium - Binder Price Plan] )
VAR EXP_B = VALUES ( 'Consolidated Sheet'[EXP - Binder Price Plan] )
VAR EITL = VALUES ( 'Consolidated Sheet'[EITL - Binder Price Plan] )
VAR P1_Max = SELECTEDVALUE ( 'IRR Retina'[P1 Max - Binder Price Plan] )
VAR P2_Max = SELECTEDVALUE ( 'IRR Retina'[P2 Max - Binder Price Plan] )
RETURN
IF (
ISBLANK ( P1_Max ) || ISBLANK ( P2_Max ),
BLANK (),
SWITCH (
TRUE (),
P1_Max = P2_Max, "Retained",
P1_Max = EXP_B && P2_Max IN UNION ( EITL, ITL, GTP, GBS ), "Downgrade",
P1_Max = EITL && P2_Max IN UNION ( ITL, GTP, GBS ), "Downgrade",
P1_Max = ITL && P2_Max IN UNION ( GTP, GBS ), "Downgrade",
P1_Max = EXP_B && P2_Max = RB, "Upgrade",
P1_Max = EITL && P2_Max IN UNION ( RB, EXP_B ), "Upgrade",
P1_Max = ITL && P2_Max IN UNION ( RB, EXP_B, EITL ), "Upgrade",
"Cancelled"
)
)
In this, P1_Max and P2_Max cannot have multiple values but the rest of the variables can.
Hi,
Have you followed the DAX formula posted by AlexisOlson to find the solution to your problem?
If so, would you like to mark his reply as a solution so that others can learn from it too?
For more info about the DAX function SelectedValue() in the Power BI, please refer to this link:
https://docs.microsoft.com/en-us/dax/selectedvalue-function
Thanks in advance!
How to Get Your Question Answered Quickly
Best Regards,
Community Support Team _Robert Qin
Hi @Anonymous
Try this:
Migration Status =
VAR RB =
VALUES ( 'Consolidated Sheet'[RB] )
VAR GTP =
VALUES ( 'Consolidated Sheet'[GTP] )
VAR GBS =
VALUES ( 'Consolidated Sheet'[GBS] )
VAR ITL =
VALUES ( 'Consolidated Sheet'[ITL - EXP non premium - EITL - Non premium - Binder Price Plan] )
VAR EXP_B =
VALUES ( 'Consolidated Sheet'[EXP - Binder Price Plan] )
VAR EITL =
VALUES ( 'Consolidated Sheet'[EITL - Binder Price Plan] )
RETURN
IF (
HASONEVALUE ( 'IRR Retina'[P1 Max - Binder Price Plan] ),
IF (
HASONEVALUE ( 'IRR Retina'[P2 Max - Binder Price Plan] ),
SWITCH (
TRUE (),
'IRR Retina'[P1 Max - Binder Price Plan] = 'IRR Retina'[P2 Max - Binder Price Plan], "Reatined",
'IRR Retina'[P1 Max - Binder Price Plan]
IN EXP_B
&& 'IRR Retina'[P2 Max - Binder Price Plan] IN UNION ( EITL, ITL, GTP, GBS ), "Downgrade",
'IRR Retina'[P1 Max - Binder Price Plan]
IN EITL
&& 'IRR Retina'[P2 Max - Binder Price Plan] IN UNION ( ITL, GTP, GBS ), "Downgrade",
'IRR Retina'[P1 Max - Binder Price Plan]
IN ITL
&& 'IRR Retina'[P2 Max - Binder Price Plan] IN UNION ( GTP, GBS ), "Downgrade",
'IRR Retina'[P1 Max - Binder Price Plan]
IN EXP_B
&& 'IRR Retina'[P2 Max - Binder Price Plan] IN RB, "Upgrade",
'IRR Retina'[P1 Max - Binder Price Plan]
IN EITL
&& 'IRR Retina'[P2 Max - Binder Price Plan] IN UNION ( EXP_B, RB ), "Upgrade",
'IRR Retina'[P1 Max - Binder Price Plan]
IN ITL
&& 'IRR Retina'[P2 Max - Binder Price Plan] IN UNION ( EITL, RB, EXP_B ), "Upgrade",
"Cancelled"
)
)
)
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: www.linkedin.com/in/vahid-dm/
@Anonymous This looks like a reasonable interpretation for how to handle multiple values. However, the naked P1, P2 column references will probably still cause problems.
This is what my version would look like using this logic:
Migration Status =
VAR RB = VALUES ( 'Consolidated Sheet'[RB] )
VAR GTP = VALUES ( 'Consolidated Sheet'[GTP] )
VAR GBS = VALUES ( 'Consolidated Sheet'[GBS] )
VAR ITL = VALUES ( 'Consolidated Sheet'[ITL - EXP non premium - EITL - Non premium - Binder Price Plan] )
VAR EXP_B = VALUES ( 'Consolidated Sheet'[EXP - Binder Price Plan] )
VAR EITL = VALUES ( 'Consolidated Sheet'[EITL - Binder Price Plan] )
VAR P1_Max = SELECTEDVALUE ( 'IRR Retina'[P1 Max - Binder Price Plan] )
VAR P2_Max = SELECTEDVALUE ( 'IRR Retina'[P2 Max - Binder Price Plan] )
RETURN
IF (
ISBLANK ( P1_Max ) || ISBLANK ( P2_Max ),
BLANK (),
SWITCH (
TRUE (),
P1_Max = P2_Max, "Retained",
P1_Max = EXP_B && P2_Max IN UNION ( EITL, ITL, GTP, GBS ), "Downgrade",
P1_Max = EITL && P2_Max IN UNION ( ITL, GTP, GBS ), "Downgrade",
P1_Max = ITL && P2_Max IN UNION ( GTP, GBS ), "Downgrade",
P1_Max = EXP_B && P2_Max = RB, "Upgrade",
P1_Max = EITL && P2_Max IN UNION ( RB, EXP_B ), "Upgrade",
P1_Max = ITL && P2_Max IN UNION ( RB, EXP_B, EITL ), "Upgrade",
"Cancelled"
)
)
In this, P1_Max and P2_Max cannot have multiple values but the rest of the variables can.
I prefer to use SELECTEDVALUES instead of VALUES since it's just a shortcut for IF ( HASONEVALUE ( ... ), VALUES ( ... ) ).
Try this:
Migration Status =
VAR RB = SELECTEDVALUE ( 'Consolidated Sheet'[RB] )
VAR GTP = SELECTEDVALUE ( 'Consolidated Sheet'[GTP] )
VAR GBS = SELECTEDVALUE ( 'Consolidated Sheet'[GBS] )
VAR ITL =
SELECTEDVALUE ( 'Consolidated Sheet'[ITL - EXP non premium - EITL - Non premium - Binder Price Plan] )
VAR EXP_B = SELECTEDVALUE ( 'Consolidated Sheet'[EXP - Binder Price Plan] )
VAR EITL = SELECTEDVALUE ( 'Consolidated Sheet'[EITL - Binder Price Plan] )
VAR P1_Max = SELECTEDVALUE ( 'IRR Retina'[P1 Max - Binder Price Plan] )
VAR P2_Max = SELECTEDVALUE ( 'IRR Retina'[P2 Max - Binder Price Plan] )
RETURN
SWITCH (
TRUE (),
P1_Max = P2_Max, "Retained",
P1_Max = EXP_B && P2_Max IN { EITL, ITL, GTP, GBS }, "Downgrade",
P1_Max = EITL && P2_Max IN { ITL, GTP, GBS }, "Downgrade",
P1_Max = ITL && P2_Max IN { GTP, GBS }, "Downgrade",
P1_Max = EXP_B && P2_Max = RB, "Upgrade",
P1_Max = EITL && P2_Max IN { RB, EXP_B }, "Upgrade",
P1_Max = ITL && P2_Max IN { RB, EXP_B, EITL }, "Upgrade",
"Cancelled"
)
Wow this is much cleaner and I love the SELECTEDVALUES! But we are so close, it looks like im getting all "retained" and when I removed that (too see if it just wasnt reading the variables), I got all "Downgrade". It looks like it taking the first value and not going down to the other conditions.
Do you have exactly one value selected for the relevant variables?
If you're getting all "Retained", then I'm guessing that's because P1_Max and P2_Max are both blank because SELECTEDVALUES is detecting multiple values for them.
No not just one, each variable has multiple values (RB has 4 but ITL has 38 for example) inside of it.
OK. I don't know how the logic is supposed to work if there are multiple values in your case. It definitely gets more complicated since checking equality doesn't really work.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
47 | |
26 | |
19 | |
14 | |
10 |
User | Count |
---|---|
57 | |
49 | |
44 | |
18 | |
18 |