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

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

Reply
jlrozano
New Member

Variables performance on filter

Hi,

 

I already read post about variables perfomances and this article: Optimizing DAX expressions involving multiple measures - SQLBI. In them, it is recommended to always use variables and the least number of queries possible. However, my experience is the opposite.

I have a matrix by categories and years. For certain categories, I have to perform an additional filter:

 

VAR CategoryId = SELECTEDVALUE(Categories[Id])

VAR FilterText = SWITCH(CategoryId,
        110, "A",
        111, "B",
        62, "C",
        126, "D",
        127, "E", BLANK())

RETURN IF(ISBLANK(FilterText), SUMX(Facts,[Value]), SUMX(FILTER(Facts, [NegocioBP] = FIlterText), [Value])

For this code, i get times over 35000 - 40000 ms. But if use this other code I get times over 950 -1100 ms.

VAR CategoryId = SELECTEDVALUE(Categories[Id])

VAR A = SUMX(FILTER(Facts,   [NegocioBP] = "A" ),[Value])
VAR B = SUMX(FILTER(Facts,   [NegocioBP] = "B" ),[Value])
VAR C = SUMX(FILTER(Facts,   [NegocioBP] = "C" ),[Value])
VAR D = SUMX(FILTER(Facts,   [NegocioBP] = "D" ),[Value])
VAR E = SUMX(FILTER(Facts,  [NegocioBP] = "D" ),[Value])
VAR F = SUMX(Facts,  [Value])

RETURN 
SWITCH(CategoryId,
        110, A,
        111, B,
        62, C,
        126, D,
        127, E, F)

Why?..

 

Thanks.

2 REPLIES 2
amitchandak
Super User
Super User

@jlrozano , In the first case in the second sumx in return. code has to execute for all rows

SUMX(Facts, [NegocioBP] = FIlterText)

 

while the second code is at the visual level on the category of row

 

That is what I can get

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi,

Thanks for the reply. I don't understand why first case is for all rows an the second is a visual level. I think both is at the visual level on the category of row. Both received the same dataset and filter it, but the fisrt one with sumx and a variable condition and the second perform six filter, one for each case, with a fixed condition.

 

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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