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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
sean_hong
Frequent Visitor

How to enhance the refresh performance regarding Switch funtion

Hi all, 

 

I am quite new for PowerBI.  I would like to ask for help. 

 

I made the PowerBI dashboard which reads the report slowly. 

I assume that the below DAX affects the whole dashboard performance. 

Is there any way to enhance this using VAR function?

DAX_name =
SWITCH(
TRUE()
, SELECTEDVALUE(wbr[measure_type]) IN {""name1", "name2", "name3"}, IFERROR( SUM(table[measure1]), 0)
, SELECTEDVALUE(wbr[measure_type]) IN {"name4", "name5", "name6"}, divide(sum(table[measure1]), sum(table[measure2]), 0)
, SELECTEDVALUE(wbr[measure_type]) IN {"name7"}, IFERROR( CALCULATE(Table2[measure3]*100), 0)
, SELECTEDVALUE(wbr[measure_type]) IN {"name8", "name9"}, (divide( sum(table[measure1]), sum(table[measure2]), 0)*1000000)
, SELECTEDVALUE(wbr[measure_type]) IN {"name10"}, IFERROR( CALCULATE( SUM(table[measure1]), LASTDATE('calendar'[Date]) ), 0)
, SELECTEDVALUE(wbr[measure_type]) IN {"name11"}, IFERROR( CALCULATE( ( (sum(table[measure1])/sum(table[measure2]))*100 ), LASTDATE('calendar'[Date]) ), 0)
, SELECTEDVALUE(wbr[measure_type]) IN {"name12", "name13", "name14"}, divide( sum(table[measure1]), sum(table[measure2]), 0)*100
)
1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @sean_hong ,

 

You can try the following measure.

DAX_name =
var _a=SELECTEDVALUE(wbr[measure_type]) IN {"name1", "name2", "name3"}
var _b=IFERROR( SUM(table[measure1]), 0)
var _c=SELECTEDVALUE(wbr[measure_type]) IN {"name4", "name5", "name6"}
var _d=divide(sum(table[measure1]), sum(table[measure2]), 0)
var _e=SELECTEDVALUE(wbr[measure_type]) IN {"name7"}
var _f=IFERROR( CALCULATE(Table2[measure3]*100), 0)
var _g=SELECTEDVALUE(wbr[measure_type]) IN {"name8", "name9"}
var _h=divide( sum(table[measure1]),sum(table[measure2]), 0)*1000000
.....

var _result=
SWITCH(
TRUE()
, _a, _b
, _c, _d
, _e, _f
,_g , _h)

return _result

vtangjiemsft_0-1669946284552.png

Please refer to the following document for more information.

Use variables to improve your DAX formulas - DAX | Microsoft Learn

VAR – DAX Guide

Using Variables within DAX - (powerbi.tips)

 

Best Regards,

Neeko Tang

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

2 REPLIES 2
sean_hong
Frequent Visitor

Fantastic!. It perfectly works. Thak you so much !!

v-tangjie-msft
Community Support
Community Support

Hi @sean_hong ,

 

You can try the following measure.

DAX_name =
var _a=SELECTEDVALUE(wbr[measure_type]) IN {"name1", "name2", "name3"}
var _b=IFERROR( SUM(table[measure1]), 0)
var _c=SELECTEDVALUE(wbr[measure_type]) IN {"name4", "name5", "name6"}
var _d=divide(sum(table[measure1]), sum(table[measure2]), 0)
var _e=SELECTEDVALUE(wbr[measure_type]) IN {"name7"}
var _f=IFERROR( CALCULATE(Table2[measure3]*100), 0)
var _g=SELECTEDVALUE(wbr[measure_type]) IN {"name8", "name9"}
var _h=divide( sum(table[measure1]),sum(table[measure2]), 0)*1000000
.....

var _result=
SWITCH(
TRUE()
, _a, _b
, _c, _d
, _e, _f
,_g , _h)

return _result

vtangjiemsft_0-1669946284552.png

Please refer to the following document for more information.

Use variables to improve your DAX formulas - DAX | Microsoft Learn

VAR – DAX Guide

Using Variables within DAX - (powerbi.tips)

 

Best Regards,

Neeko Tang

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

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors