Forum Discussion
DAX for Previous calculations
- 5 years ago
Hi Anonymous ,
I made some changes to your PBIX file and now we can get the correct value. This is the PBIX file.
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
WinnizIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
Based on your description, I create the following sample data. I first create a calculated column:
Worknum = WEEKNUM( 'Table'[WEEK ENDING], 2 )Then create the following measures:
Last Week =
CALCULATE(
SUM('Table'[STARTS]),
LASTDATE( 'Table'[WEEK ENDING] )
)The cumulative starts for the same period of the previous year:
Same Period =
var _worknum =
CALCULATE(
MAX('Table'[Worknum]),
DATESYTD('Table'[WEEK ENDING])
)
var result =
CALCULATE(
SUM('Table'[STARTS]),
FILTER(
ALL('Table'),
WEEKNUM('Table'[WEEK ENDING],2) = _worknum
&& 'Table'[WEEK ENDING] <> MAX('Table'[WEEK ENDING])
)
)
return resultLast Month =
CALCULATE(
SUM('Table'[STARTS]),
DATESMTD('Table'[WEEK ENDING])
)Last Year =
CALCULATE(
SUM('Table'[STARTS]),
DATESYTD('Table'[WEEK ENDING])
)Previous Week =
CALCULATE(
SUM('Table'[STARTS]),
DATEADD(
LASTDATE( 'Table'[WEEK ENDING] ),
-7,
DAY
)
)Previous Month =
CALCULATE(
SUM('Table'[STARTS]),
PREVIOUSMONTH(
LASTDATE('Table'[WEEK ENDING])
)
)Previous Year =
CALCULATE(
SUM('Table'[STARTS]),
PREVIOUSYEAR('Table'[WEEK ENDING])
)
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Winniz,
Thank you for the solution I tried to implement the same in my report but I am getting Previous month and Previous Week as null. Also the the Starts is same as Last Week and Last month. Can you please tell me where am I going wrong
- v-kkf-msft5 years ago
Community Support
Hi Anonymous ,
That may be caused by our different models. This is my PBIX file, you can see the difference.
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
WinnizIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous5 years agoNot applicable
Hi Winniz,
I have seen the file you sent its may be beacuse of the date hierarchy I am using. I am also sharing my file, please suggest
- v-kkf-msft5 years ago
Community Support
Hi Anonymous ,
I can't access your files after clicking on the link, you need to give me access permissions. You can refer to the following document:
Share SharePoint files or folders - Office Support (microsoft.com)
Best Regards,
Winniz