Forum Discussion
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
Stock_Case_LastDate = SUMX (
VALUES ( 'Sold to party' ),
CALCULATE ( SUM ( Stock[Case]),LASTDATE( ( Stock[Stock_Date] ) )
))
get this error
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
8 Replies
- Pragati11
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
- AnonymousNot 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.- Pragati11
Super User
Hi Anonymous ,
I am just trying to understand the requirement here.
Thanks,
Pragati
- amitchandak
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-YTD-LYTD-Week-Over-Week/m-p/1051626#M184
Appreciate your Kudos. - AnonymousNot applicablenanutum
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- nanutum
Helper I
i very confused this 2 measure is not error in lastweek
- AnonymousNot applicable
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