cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jatneerjat
Helper V
Helper V

Max(Date) vs Lastdate(Date): which one should use for better performance

Hi,

 

As i am working on improving performance of measures, which function should i use to get the latest date from a date table?

 

Max(Date) or LastDate(Date)

 

Thanks

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

in this article there is a short paragraph about the 2
https://www.sqlbi.com/articles/semi-additive-measures-in-dax/


basically LASTDATE returns a table of one column and one row, while MAX returns scalar value
accoriding to the article this code is equivalent to LASTDATE

        FILTER (
            ALL( 'Date'[Date] ), 
            'Date'[Date] = MAX ( 'Date'[Date] )
        )

so to answer your question if you need a scalar I'd use MAX

on optimization in general - I recommend watching this video and in avoiding iterator functions on full tables if possible
https://www.sqlbi.com/tv/optimizing-dax-queries/



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Proud to be a Super User!

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @jatneerjat,

 

Have you solved your problem?

 

If you have solved, please accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Stachu
Community Champion
Community Champion

in this article there is a short paragraph about the 2
https://www.sqlbi.com/articles/semi-additive-measures-in-dax/


basically LASTDATE returns a table of one column and one row, while MAX returns scalar value
accoriding to the article this code is equivalent to LASTDATE

        FILTER (
            ALL( 'Date'[Date] ), 
            'Date'[Date] = MAX ( 'Date'[Date] )
        )

so to answer your question if you need a scalar I'd use MAX

on optimization in general - I recommend watching this video and in avoiding iterator functions on full tables if possible
https://www.sqlbi.com/tv/optimizing-dax-queries/



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Proud to be a Super User!

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.