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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Switch DAX formula error - Tricky

Hi Experts

 

Cann see the wood for the tree as to what i am doing wrong with the following switch when using variables...

 

% Reported Central 2 = 
VAR ReportingMeasure = SELECTEDVALUE(Reporting[Reporting])
VAR InorganicMeasure = SELECTEDVALUE(InOrganic[InOrganic])

VAR NSales =
        SWITCH(
    ReportingMeasure, "Reported", [NSvPY1% (Reported PY)],BLANK()) 
VAR NSales1 = 
        SWITCH(
    ReportingMeasure, "NOE",[NSvPY3% (NOE @ PY Rate)], BLANK())        
VAR Organic = 
        SWITCH(
    ReportingMeasure, "Organic",[% Organic Growth Movement], BLANK())    
Return

SWITCH(NSales, "Reported", NSales1, "NOE", Organic, "Organic",BLANK()) 
2 ACCEPTED SOLUTIONS
OwenAuger
Super User
Super User

Hi @Anonymous

From the code you've posted, the SWITCH function call on the very last line looks strange.

Specifically, the final SWITCH's intended first argument seems to be missing, and the other pairs of arguments seem to be the wrong way around.

I'm guessing a bit, but did you intend:

SWITCH ( ______, "Reported", NSales, "NOE", NSales1, "Organic", Organic, BLANK() )

Also you haven't used the InorganicMeasure variable after defining it. Not sure if that is supposed to be the first argument of SWITCH here.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

Sample data would help tremendously. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

That being said, what error are you getting? Is this a column or measure?

 

The way you have it structured, I believe you want this instead:

 

% Reported Central 2 = 
VAR ReportingMeasure = SELECTEDVALUE(Reporting[Reporting])
VAR InorganicMeasure = SELECTEDVALUE(InOrganic[InOrganic])

VAR NSales =
        SWITCH(
		ReportingMeasure, 
		"Reported", [NSvPY1% (Reported PY)],
		BLANK()
	)

VAR NSales1 =    
        SWITCH(
    		ReportingMeasure,
		"NOE",[NSvPY3% (NOE @ PY Rate)], 
		BLANK()
	)  

Var Org1 =         
        SWITCH(       
    		InorganicMeasure, 
		"Organic",[% Organic Growth Movement],
		BLANK())        

Return

SWITCH(
	ReportingMeasure, 
	"Reported",NSales,
	"NOE",NSales1, 
	Org1
)

But this seems like it could be way simplified:

 

% Reported Central 2 = 
VAR ReportingMeasure = SELECTEDVALUE(Reporting[Reporting])
VAR InorganicMeasure = SELECTEDVALUE(InOrganic[InOrganic])

Var Org1 =         
        SWITCH(       
    		InorganicMeasure, 
		"Organic",[% Organic Growth Movement],
		BLANK())        

RETURN
SWITCH(
	ReportingMeasure,
	"Reported",[NSvPY1% (Reported PY)],
	"NOE",[NSvPY3% (NOE @ PY Rate)],
	Org1
)


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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
OwenAuger
Super User
Super User

Hi @Anonymous

From the code you've posted, the SWITCH function call on the very last line looks strange.

Specifically, the final SWITCH's intended first argument seems to be missing, and the other pairs of arguments seem to be the wrong way around.

I'm guessing a bit, but did you intend:

SWITCH ( ______, "Reported", NSales, "NOE", NSales1, "Organic", Organic, BLANK() )

Also you haven't used the InorganicMeasure variable after defining it. Not sure if that is supposed to be the first argument of SWITCH here.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn
Anonymous
Not applicable

thanks owen - i see the error...much appreciated

Anonymous
Not applicable

Hi Expets

 

Need some help as i cannot still see the error here on the switch function...

Should read as follows: if from reporting measure either NOE or Reported are selected then return below, then if niether NOE or Reported are selected then Inorganic

 

% Reported Central 2 = 
VAR ReportingMeasure = SELECTEDVALUE(Reporting[Reporting])
VAR InorganicMeasure = SELECTEDVALUE(InOrganic[InOrganic])

VAR NSales =
        SWITCH(
    ReportingMeasure, "Reported", [NSvPY1% (Reported PY)],BLANK())
VAR NSales1 =    
        SWITCH(
    ReportingMeasure, "NOE",[NSvPY3% (NOE @ PY Rate)], BLANK())  
Var Org1 =         
        SWITCH(       
    InorganicMeasure, "Organic",[% Organic Growth Movement],BLANK())        

Return

SWITCH(ReportingMeasure, "Reported", NSales, "NOE", NSales1, Org1,BLANK()) 

Sample data would help tremendously. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

That being said, what error are you getting? Is this a column or measure?

 

The way you have it structured, I believe you want this instead:

 

% Reported Central 2 = 
VAR ReportingMeasure = SELECTEDVALUE(Reporting[Reporting])
VAR InorganicMeasure = SELECTEDVALUE(InOrganic[InOrganic])

VAR NSales =
        SWITCH(
		ReportingMeasure, 
		"Reported", [NSvPY1% (Reported PY)],
		BLANK()
	)

VAR NSales1 =    
        SWITCH(
    		ReportingMeasure,
		"NOE",[NSvPY3% (NOE @ PY Rate)], 
		BLANK()
	)  

Var Org1 =         
        SWITCH(       
    		InorganicMeasure, 
		"Organic",[% Organic Growth Movement],
		BLANK())        

Return

SWITCH(
	ReportingMeasure, 
	"Reported",NSales,
	"NOE",NSales1, 
	Org1
)

But this seems like it could be way simplified:

 

% Reported Central 2 = 
VAR ReportingMeasure = SELECTEDVALUE(Reporting[Reporting])
VAR InorganicMeasure = SELECTEDVALUE(InOrganic[InOrganic])

Var Org1 =         
        SWITCH(       
    		InorganicMeasure, 
		"Organic",[% Organic Growth Movement],
		BLANK())        

RETURN
SWITCH(
	ReportingMeasure,
	"Reported",[NSvPY1% (Reported PY)],
	"NOE",[NSvPY3% (NOE @ PY Rate)],
	Org1
)


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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

thanks Greg i see the error. much appericated as always. excellent feedback

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors