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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
nanutum
Helper I
Helper I

LASTDATE ERROR MDXSCRIPT PLEASE HELP

i have 2 meaure can used normally 

but today get error below please help

 

 

Stock_Case_LastDate = SUMX (
    VALUES ( 'Sold to party' ),
    CALCULATE ( SUM ( Stock[Case]),LASTDATE( ( Stock[Stock_Date] ) )
))

 

 

get this error 

 

LASTDATE_01.png

 

 

Stock_Case_LastDate = SUMX (
    VALUES ( 'Sold to party' ),
    CALCULATE ( SUM ( Stock[Case]),LASTDATE( ( Stock[Stock_Date] ) )
))

 

 get this error

LASTDATE_02.png

 

1 ACCEPTED SOLUTION

Hello @nanutum ,

Can you try modifying the DAX expression for the measure as follows:

Stock_Case_LastDate = 
var maxDate = CALCULATE(MAX(Stock[Stock_Date]))
RETURN
CALCULATE(SUM(Stock[Case]), ALL(Stock), Stock[Stock_Date] = maxDate)

Thank you

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

8 REPLIES 8
v-eqin-msft
Community Support
Community Support

Hi @nanutum ,

Since there is no data sample and expected output , I’m not sure why the LASTDATE() function not works.

As this article said, 'firstdate' and 'lastdate' function not works if your date table contains duplicate records.

If you're using a fact table where the same date can be repeated more than once, you should use MIN and MAX instead.

 

If you have any further questions ,please upload your pbix file after doing mask sensitive data.

 

Best Regards,

Eyelyn Qin

Anonymous
Not applicable

@nanutum

As the error clearly says, LASTDATE is a table function that operates on a column of dates but the dates must be UNIQUE. This function should be used on a proper Date table in the model, not just on any column that happens to store dates.

Please create a proper calendar in your model, connect to your fact table and you'll be good to go.

By the way, your model should be a star schema. Please refer to this: https://docs.microsoft.com/en-us/power-bi/guidance/star-schema#star-schema-overview

i very confused this 2 measure is not error in lastweek

Hello @nanutum ,

Can you try modifying the DAX expression for the measure as follows:

Stock_Case_LastDate = 
var maxDate = CALCULATE(MAX(Stock[Stock_Date]))
RETURN
CALCULATE(SUM(Stock[Case]), ALL(Stock), Stock[Stock_Date] = maxDate)

Thank you

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

amitchandak
Super User
Super User

@nanutum , Create a date table join with this and use date from there.

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

Pragati11
Super User
Super User

HI @nanutum ,

 

Can you please elaborate on why you are using LASTDATE function in your DAX?

You can use MAX function also.

 

Add details please: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Anonymous
Not applicable

@Pragati11

The simple answer is: because LASTDATE returns a one-row-one-column table which can be used under CALCULATE as a filter. MAX is a scalar function and hence, it can't be used directly under CALCULATE.

Hi @Anonymous ,

 

I am just trying to understand the requirement here.

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.