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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
krampit1
Helper I
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 formulaExplanation formulaProblemProblem

 

1 ACCEPTED SOLUTION

@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


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
krampit1
Helper I
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. 

Switch.png

Greg_Deckler
Super User
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.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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] )
)

@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


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.