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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
nivh
New Member

Optimize the DAX measure to Improve the visual

Hello,

I have this DAX measure and I've Identified this is the only measure that breaks my visualization table (due to limited available resources). I would appreciate it if anyone could help how to optimize this DAX measure to visualize without breaking the table.

 

Sales Wk (-1) =
VAR TodayDate =
    TODAY ()
VAR LastWeek =
    WEEKNUM ( TodayDate, 1 ) - 1
VAR CurrentYear =
    YEAR ( TodayDate )
RETURN
    CALCULATE (
        [Sales],
        FILTER (
            'Sales table',
            WEEKNUM ( 'Sales table'[Order Date], 1 ) = LastWeek
                && YEAR ( 'Sales table'[Order Date] ) = CurrentYear
        ),USERELATIONSHIP ( 'Sales table'[_sid], 'Member'[Sales_Table_id] )
)
  Thank you
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @nivh ,
Thanks for @collinsg  reply

Based on your description, you can try to optimize your dax in these areas:
First, avoid using TODAY() in variables. This function recalculates for each line, which can take up a lot of resources. Instead, if possible, compute dates outside of the metric.
Second, simplify the FILTER function. Filtering an entire table can be slow. Try filtering columns instead.
Finally, use the ALL function. This helps remove any existing filters on the columns you are using.

Sample Dax

Sales Wk (-1) =
VAR TodayDate = TODAY()
VAR LastWeek = WEEKNUM(TodayDate, 1) - 1
VAR CurrentYear = YEAR(TodayDate)
RETURN
    CALCULATE(
        [Sales],
        FILTER(
            ALL('Sales table'),
            WEEKNUM('Sales table'[Order Date], 1) = LastWeek &&
            YEAR('Sales table'[Order Date]) = CurrentYear
        ),
        USERELATIONSHIP('Sales table'[_sid], 'Member'[Sales_Table_id])
    )

 

Best regards,
Albert He


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

3 REPLIES 3
Anonymous
Not applicable

Hi @nivh ,
Thanks for @collinsg  reply

Based on your description, you can try to optimize your dax in these areas:
First, avoid using TODAY() in variables. This function recalculates for each line, which can take up a lot of resources. Instead, if possible, compute dates outside of the metric.
Second, simplify the FILTER function. Filtering an entire table can be slow. Try filtering columns instead.
Finally, use the ALL function. This helps remove any existing filters on the columns you are using.

Sample Dax

Sales Wk (-1) =
VAR TodayDate = TODAY()
VAR LastWeek = WEEKNUM(TodayDate, 1) - 1
VAR CurrentYear = YEAR(TodayDate)
RETURN
    CALCULATE(
        [Sales],
        FILTER(
            ALL('Sales table'),
            WEEKNUM('Sales table'[Order Date], 1) = LastWeek &&
            YEAR('Sales table'[Order Date]) = CurrentYear
        ),
        USERELATIONSHIP('Sales table'[_sid], 'Member'[Sales_Table_id])
    )

 

Best regards,
Albert He


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

 

Thank you @Anonymous This helped, I created a separate measure for [TodayDate] and It worked.

collinsg
Super User
Super User

Good day @nivh ,

A good place to start may be Power BI Antipatterns #9: Filtering whole tables, part I by Daniil Maslyuk. Your FILTER filters a whole table and may benefit from just filtering a column.

Hope this helps

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.