cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

Helper I

## With examples: SWITCH-statement skips "value3" and jumps to "result3"

Hi all,

My problem: I'm not able to add a third value (= [Value3] to evaluate in my SWITCH-statement. It automatically jumps to [Result3].

Explanation:

I'm using a two SWITCH-statements.
The first one is to determine if an employee has:
1) a salesfactor (e.g. hourly wage of € 10,00 * salesfactor 220% = €22,00), or;
2) a fixed sales price (e.g. €25,00)

If an employee has a salesfactor then SWITCH#2 will be activated, where I want to add three conditions:

1) Weekday (Mo-Fr) & No holiday;
2) Saturday & No holiday;

3) Sunday & No holiday;

The problem is that I'm not able to add the 3th condition (= Sunday & No holiday).
My SWITCH-statement automatically jumps to [Result3] and doesn't let me fill in a [Value3] to evaluate.
As you can see in picture 2, adding a comma after [Result2] doesn't show [Value3], but [Result3].

I've tried everything, but it doesn't give me a solution. Anyone can help me?

Explanation formulaProblem

1 ACCEPTED SOLUTION
Super User

@krampit1 To improve readability I would recommend this approach and I have noted where conditions and values should go:

``````SalesAmount =
VAR VerkooptariefNormaal =
RELATED ( Personeel[Uurloon] ) * RELATED ( Personeel[Verkoopfactor] )
VAR VerkooptariefZaterdag =
VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_zaterdag] )
VAR VerkooptariefZondag =
VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_zondag] )
VAR __Value1 =
IF (
'Eigen overzichten'[UrenOVW1] > 0,
'Eigen overzichten'[UrenOVW1] * ( VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_ovw1] ) ),
0
)
VAR __Value2 =
IF (
'Eigen overzichten'[UrenOVW2] > 0,
'Eigen overzichten'[UrenOVW2] * ( VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_ovw2] ) ),
0
)

RETURN
SWITCH (
TRUE (),
RELATED ( Personeel[Verkoopfactor] ) > 0,
SWITCH (
TRUE (),
'Eigen overzichten'[WeekofWeekend] = "Weekdag"
&& 'Eigen overzichten'[Feestdag] = "Geen feestdag",
'Eigen overzichten'[UrenNormaal] * VerkooptariefNormaal + __Value1 + __Value2,
'Eigen overzichten'[Weekdag] = "Zaterdag"
&& 'Eigen overzichten'[Feestdag] = "Geen feestdag",
'Eigen overzichten'[UrenNormaal] * VerkooptariefZaterdag + __Value1 + __Value2, //if this is the last condition, remove ,
//next condition goes here with ,
//next value goes here
), //ends 2nd SWITCH
RELATED ( Personeel[Verkoopprijs_vast] ) > 0, 'Eigen overzichten'[UrenNormaal] * RELATED ( Personeel[Verkoopprijs_vast] )
) //Ends first SWITCH``````

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
4 REPLIES 4
Helper I

Thank you for your reply @Greg_Deckler. I've added the code as text and used Daxformatter.com. Thank you for that recommendation. The issue still remains. I've added a comma at the end (=red circle), but the statement still shows [Result3] first and no [Value3] at all.

Super User

@krampit1 Please paste your code as text and please use the daxformatter.com to properly format your code. I can see a ton of improvements that will improve readability of your code. Consider that it may just be the case of the intellisense getting confused and not really an issue.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Helper I
SalesAmount =
VAR VerkooptariefNormaal =
RELATED ( Personeel[Uurloon] ) * RELATED ( Personeel[Verkoopfactor] )
VAR VerkooptariefZaterdag =
VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_zaterdag] )
VAR VerkooptariefZondag =
VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_zondag] )
RETURN
SWITCH (
TRUE (),
RELATED ( Personeel[Verkoopfactor] ) > 0,
SWITCH (
TRUE (),
'Eigen overzichten'[WeekofWeekend] = "Weekdag"
&& 'Eigen overzichten'[Feestdag] = "Geen feestdag",
'Eigen overzichten'[UrenNormaal] * VerkooptariefNormaal
+ IF (
'Eigen overzichten'[UrenOVW1] > 0,
'Eigen overzichten'[UrenOVW1]
* ( VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_ovw1] ) )
)
+ IF (
'Eigen overzichten'[UrenOVW2] > 0,
'Eigen overzichten'[UrenOVW2]
* ( VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_ovw2] ) )
),
'Eigen overzichten'[Weekdag] = "Zaterdag"
&& 'Eigen overzichten'[Feestdag] = "Geen feestdag",
'Eigen overzichten'[UrenNormaal] * VerkooptariefZaterdag
+ IF (
'Eigen overzichten'[UrenOVW1] > 0,
'Eigen overzichten'[UrenOVW1]
* ( VerkooptariefZaterdag * RELATED ( Opdrachtgever[Tarief_ovw1] ) )
)
+ IF (
'Eigen overzichten'[UrenOVW2] > 0,
'Eigen overzichten'[UrenOVW2]
* ( VerkooptariefZaterdag * RELATED ( Opdrachtgever[Tarief_ovw2] ) )
)
),
RELATED ( Personeel[Verkoopprijs_vast] ) > 0, 'Eigen overzichten'[UrenNormaal] * RELATED ( Personeel[Verkoopprijs_vast] )
)
Super User

@krampit1 To improve readability I would recommend this approach and I have noted where conditions and values should go:

``````SalesAmount =
VAR VerkooptariefNormaal =
RELATED ( Personeel[Uurloon] ) * RELATED ( Personeel[Verkoopfactor] )
VAR VerkooptariefZaterdag =
VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_zaterdag] )
VAR VerkooptariefZondag =
VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_zondag] )
VAR __Value1 =
IF (
'Eigen overzichten'[UrenOVW1] > 0,
'Eigen overzichten'[UrenOVW1] * ( VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_ovw1] ) ),
0
)
VAR __Value2 =
IF (
'Eigen overzichten'[UrenOVW2] > 0,
'Eigen overzichten'[UrenOVW2] * ( VerkooptariefNormaal * RELATED ( Opdrachtgever[Tarief_ovw2] ) ),
0
)

RETURN
SWITCH (
TRUE (),
RELATED ( Personeel[Verkoopfactor] ) > 0,
SWITCH (
TRUE (),
'Eigen overzichten'[WeekofWeekend] = "Weekdag"
&& 'Eigen overzichten'[Feestdag] = "Geen feestdag",
'Eigen overzichten'[UrenNormaal] * VerkooptariefNormaal + __Value1 + __Value2,
'Eigen overzichten'[Weekdag] = "Zaterdag"
&& 'Eigen overzichten'[Feestdag] = "Geen feestdag",
'Eigen overzichten'[UrenNormaal] * VerkooptariefZaterdag + __Value1 + __Value2, //if this is the last condition, remove ,
//next condition goes here with ,
//next value goes here
), //ends 2nd SWITCH
RELATED ( Personeel[Verkoopprijs_vast] ) > 0, 'Eigen overzichten'[UrenNormaal] * RELATED ( Personeel[Verkoopprijs_vast] )
) //Ends first SWITCH``````

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors