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
shuhn1229
Resolver I
Resolver I

Optimizing DAX Logic

Hi all,

 

I am working with a large semantic model with about 10M records. The data quality is not the best.

 

My data model involves cars and car parts (imaginary). The grain for my fact table is on the parts level. The problem is for my column of interest, with the grain of parts (preferred) values are frequently blank. When it is blank, I want logic to pull the value from the dimension table, that is related on the car level (less desired, but better than blank). I have following measure devised for this:

 

VAR SelectedAnalysisType = SELECTEDVALUE('Total Inventory'[Type])
VAR SelectedCategory = SELECTEDVALUE('Total Inventory'[Hoods], BLANK())
VAR SelectedType = SELECTEDVALUE(Cars[Hoods])

RETURN
    IF (
        SelectedAnalysisType = "Pontiac",
        IF (
            SelectedTissueCategory = BLANK(),
            SelectedType,
            SelectedCategory
        ),
        BLANK()
    )

 

However, this measure is very slow when I add it to a table visual, and can take up to 10 seconds to load 10s of thousands of records. Any ideas how to optimize this? The rest of my data model is lightning fast. Another idea is using mQuery but is less desired, since it would likely require a join and I prefer to keep these tables separate.

 

1 ACCEPTED SOLUTION
Kedar_Pande
Super User
Super User

@shuhn1229 

If the fallback logic (SelectedType when SelectedCategory is blank) is static, consider adding a calculated column in the fact table. This will avoid runtime computation:

PreferredCategory =
IF (
ISBLANK('Total Inventory'[Hoods]),
RELATED(Cars[Hoods]),
'Total Inventory'[Hoods]
)

Then, in your measure, directly reference this column instead of recalculating it:

Optimized Measure with Column =
VAR SelectedAnalysisType = SELECTEDVALUE('Total Inventory'[Type])
RETURN
IF (
SelectedAnalysisType = "Pontiac",
SELECTEDVALUE('Total Inventory'[PreferredCategory]),
BLANK()
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

View solution in original post

4 REPLIES 4
Kedar_Pande
Super User
Super User

@shuhn1229 

If the fallback logic (SelectedType when SelectedCategory is blank) is static, consider adding a calculated column in the fact table. This will avoid runtime computation:

PreferredCategory =
IF (
ISBLANK('Total Inventory'[Hoods]),
RELATED(Cars[Hoods]),
'Total Inventory'[Hoods]
)

Then, in your measure, directly reference this column instead of recalculating it:

Optimized Measure with Column =
VAR SelectedAnalysisType = SELECTEDVALUE('Total Inventory'[Type])
RETURN
IF (
SelectedAnalysisType = "Pontiac",
SELECTEDVALUE('Total Inventory'[PreferredCategory]),
BLANK()
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

not perfect but a definite improvement

Greg_Deckler
Community Champion
Community Champion

@shuhn1229 Try:

VAR SelectedAnalysisType = SELECTEDVALUE('Total Inventory'[Type])

RETURN
    IF (
        SelectedAnalysisType = "Pontiac",
        IF (
            SelectedTissueCategory = BLANK(),
            SELECTEDVALUE(Cars[Hoods]),
            SELECTEDVALUE('Total Inventory'[Hoods], BLANK())
        ),
        BLANK()
    )


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...
shuhn1229
Resolver I
Resolver I

Want to mention I tried using GPT for this with limited success and I cannot get the COALESCE function working well with this for some reason.

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.