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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
sanc_152
Helper I
Helper I

How can I replace switch using dax

Hi Eveeryone,
I am facing measure issue whilest creating switch condiiotn in measure.I am using this measure in field parameter but it is taking longer time to load and at the end it is failing .

1

ProductSales actualsFlag
110601
220700
33080blank()
440901
5501000

 

Written measure=
 1. Sales=Sum(sales)
 2. Actuals=sum(Actuals)
 3. Swith_level_flag=
Var Selected_=selectedvalue(product[flag])
return

 SWITCH(TRUE(),
Selected_=1,[Actuals],
Selected_=0 ||Selected_=BLANK(),[Sales],
 [Sales]
 )

)
I know it is simple measure but when I mausing with parameter it is failing .Is there any workaround?, I write in other way so it will be more faster@v-yueyunzh-msft 
@amitchandak 
Guys can you please help me on this.Is there any workaround I can write in another way.

 

2 ACCEPTED SOLUTIONS
v-zhangti
Community Support
Community Support

Hi, @sanc_152 

 

You can try the following methods.

Written measure = 
Var _Sales=SUM('Table'[Sales])
Var _Actuals=SUM('Table'[Actuals])
Var _Selected_=SELECTEDVALUE('Table'[Flag])
return
SWITCH(TRUE(),
_Selected_=1,_Actuals,
OR(_Selected_=0,_Selected_=BLANK()),_Sales,
 _Sales
 )

vzhangti_0-1681714015718.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Adamboer
Responsive Resident
Responsive Resident

There are a few things that could be causing performance issues with your measure. One thing to consider is the use of the selectedvalue() function, which can be expensive and slow down your measure. Instead, you could try using a disconnected table to store the flag values and use a slicer to select the desired flag value.

Additionally, you could try simplifying your measure by combining the Sales and Actuals measures into one measure using an IF statement, rather than using the SWITCH function. Here's an example of how you could write the measure:

Sales and Actuals Measure = VAR SelectedFlag = SELECTEDVALUE(Product[Flag]) RETURN IF( SelectedFlag = 1, SUM(Actuals), SUM(Sales) )

This measure uses a single IF statement to check the selected flag value and return the appropriate sum value based on the flag. This should be simpler and more efficient than using the SWITCH function.

View solution in original post

2 REPLIES 2
Adamboer
Responsive Resident
Responsive Resident

There are a few things that could be causing performance issues with your measure. One thing to consider is the use of the selectedvalue() function, which can be expensive and slow down your measure. Instead, you could try using a disconnected table to store the flag values and use a slicer to select the desired flag value.

Additionally, you could try simplifying your measure by combining the Sales and Actuals measures into one measure using an IF statement, rather than using the SWITCH function. Here's an example of how you could write the measure:

Sales and Actuals Measure = VAR SelectedFlag = SELECTEDVALUE(Product[Flag]) RETURN IF( SelectedFlag = 1, SUM(Actuals), SUM(Sales) )

This measure uses a single IF statement to check the selected flag value and return the appropriate sum value based on the flag. This should be simpler and more efficient than using the SWITCH function.

v-zhangti
Community Support
Community Support

Hi, @sanc_152 

 

You can try the following methods.

Written measure = 
Var _Sales=SUM('Table'[Sales])
Var _Actuals=SUM('Table'[Actuals])
Var _Selected_=SELECTEDVALUE('Table'[Flag])
return
SWITCH(TRUE(),
_Selected_=1,_Actuals,
OR(_Selected_=0,_Selected_=BLANK()),_Sales,
 _Sales
 )

vzhangti_0-1681714015718.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

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.