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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Optimize Dax Code

Hi,
I want to optimize below code, can you help me which DAX Functions should i use to optimize my dax code. 
 
VAR Test = Format(COALESCE(CALCULATE(SUM(Sales[Revenue]),
filter(Sales,Sales[product_status]="A" || Sales[product_status] = "C" || Sales[product_status]="Z" || Sales[product_status]="1"|| Sales[product_status]= ""),
FILTER(Sales,Product<>BLANK()),
FILTER(Sales,Sales[Sales_Date]>=Date(2022,04,01) && Sales[Sales_Date]<=Date(2022,04,30))),0),"general number")
 
Return Test
1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

 

@Anonymous 

Please try following version. It's important to better understand the data model before performaing any DAX optimization.

VAR Test =
FORMAT (
    COALESCE (
        CALCULATE (
            SUM ( Sales[Revenue] ),
            KEEPFILTERS ( Sales[product_status] IN { "A", "C", "Z", "1", "" } ),
            KEEPFILTERS ( Sales[Product] <> BLANK () ),
            KEEPFILTERS ( Sales[Sales_Date] IN CALENDAR ( "2022-04-01", "2022-04-30" ) )
        ),
        0
    ),
    "general number"
)



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@Anonymous 

USe DAX Studio: Analyzing Performance Analyzer trace in DAX Studio - YouTube

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Fowmy
Super User
Super User

 

@Anonymous 

Please try following version. It's important to better understand the data model before performaing any DAX optimization.

VAR Test =
FORMAT (
    COALESCE (
        CALCULATE (
            SUM ( Sales[Revenue] ),
            KEEPFILTERS ( Sales[product_status] IN { "A", "C", "Z", "1", "" } ),
            KEEPFILTERS ( Sales[Product] <> BLANK () ),
            KEEPFILTERS ( Sales[Sales_Date] IN CALENDAR ( "2022-04-01", "2022-04-30" ) )
        ),
        0
    ),
    "general number"
)



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy  Thanks for reply, This is working good, but one more thing i want cross check, what is execution time of both DAX queries, how can we check this ? 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.