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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
rpinxt
Impactful Individual
Impactful Individual

Switch result not working the same as the original measure

I have these numbers that are correct:

rpinxt_0-1715156204388.png

So for mth 1 2023 the LBE1 = 234,181 and LBE2 = 222,889

All fine.

 

Now I have a second matric looking like :

rpinxt_1-1715156275013.png

From prmLBE_Comp still on Addendum and from slicer Type LBE1 is selected.

As you see the nuber matches.

 

However when I also select LBE2:

rpinxt_2-1715156345157.png

It adds them together. Well first thing you will say is that its logical it would do that and I agree.

But this is my measure for TypeMax:

TypeMax =
VAR LBE_Choice = SWITCH(
    TRUE(),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Addendum",[Addendum],
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Inbound",[Inbound],
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Outbound Direct",[Outbound Direct],
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Outbound Export",[Outbound Export]
    )
RETURN
CALCULATE(LBE_Choice,'AVN MD Type'[ID] = MAX('AVN MD Type'[ID]))

 

I would expect the calculate filter to work and only take the amout belonging max MD Type ID, which is 3 in this case.

That would be LBE2 because that has the highest ID of the 2 selections.

 

And I know that this works because when I hardcode the measure Addendum in the measure:

TypeMax =
VAR LBE_Choice = SWITCH(
    TRUE(),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Addendum",[Addendum],
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Inbound",[Inbound],
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Outbound Direct",[Outbound Direct],
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Outbound Export",[Outbound Export]
    )
RETURN
CALCULATE([Addendum],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID]))
 
And look...works like a charm:
rpinxt_3-1715156762776.png

 

What is going on here?

Why does the measure work fine with the original measure but not with the Switch variant??

 

2 ACCEPTED SOLUTIONS
HotChilli
Super User
Super User

LBE_Choice gets a measure assigned to it in the switch. At that point it gets a value from that measure. That is a fixed (numeric) value. It won't change.

LBE_Choice doesn't act like a kind of dynamic variable where the name of the measure is passed to the RETURN statement and then it is evaluated in the filter context given in the CALCULATE.

 

--

"And what name of the measure is not in the Switch?" - that's not what i'm saying. The switch works fine, it's just not doing what you think it's doing.

View solution in original post

rpinxt
Impactful Individual
Impactful Individual

Ah right @HotChilli now I understand what you mean. Cannot say I find it logical from Power BI but the measure it reports gets already determined in the switch.

The Return does not really much than but pick the correct option in the switch.

 

Well for people with the same problem.
I was able to fix this issue by the following:

TypeMax =
VAR LBE_Choice = SWITCH(
    TRUE(),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Addendum",CALCULATE([Addendum],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID])),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Inbound",CALCULATE([Inbound],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID])),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Outbound Direct",CALCULATE([Outbound Direct],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID])),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Outbound Export",CALCULATE([Outbound Export],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID]))
    )
RETURN
LBE_Choice
 
Just put the calculate in the line of the switch.
Works as expected now.
I can determine which 2 option were selected and calculate te difference between the 2 outcomes.
😄

View solution in original post

4 REPLIES 4
HotChilli
Super User
Super User

LBE_Choice gets a measure assigned to it in the switch. At that point it gets a value from that measure. That is a fixed (numeric) value. It won't change.

LBE_Choice doesn't act like a kind of dynamic variable where the name of the measure is passed to the RETURN statement and then it is evaluated in the filter context given in the CALCULATE.

 

--

"And what name of the measure is not in the Switch?" - that's not what i'm saying. The switch works fine, it's just not doing what you think it's doing.

rpinxt
Impactful Individual
Impactful Individual

Ah right @HotChilli now I understand what you mean. Cannot say I find it logical from Power BI but the measure it reports gets already determined in the switch.

The Return does not really much than but pick the correct option in the switch.

 

Well for people with the same problem.
I was able to fix this issue by the following:

TypeMax =
VAR LBE_Choice = SWITCH(
    TRUE(),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Addendum",CALCULATE([Addendum],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID])),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Inbound",CALCULATE([Inbound],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID])),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Outbound Direct",CALCULATE([Outbound Direct],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID])),
    SELECTEDVALUE(prmLBE_Comp[prmLBE_Comp Value])= "Outbound Export",CALCULATE([Outbound Export],'AVN MD Type'[ID] = MAX('AVN MD Type'[ID]))
    )
RETURN
LBE_Choice
 
Just put the calculate in the line of the switch.
Works as expected now.
I can determine which 2 option were selected and calculate te difference between the 2 outcomes.
😄
HotChilli
Super User
Super User

The SWITCH version isn't working like you think it is.  The LBE_Choice is evaluated in the SWITCH.  It doesn't hold the name of the measure and then only evaluate that in the DAX on the last line.

rpinxt
Impactful Individual
Impactful Individual

Thanks @HotChilli but I am not sure if I fully understand what you mean.

 

Can my Switch not be changed so it will work?

 

And what name of the measure is not in the Switch? Looks to me like all measures I want to use are in the switch.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.