Forum Discussion
Last Year Sales Giving In-correct output
- 1 year ago
Instead of using SAMEPERIODLASTYEAR, which returns the entire month when a larger date range is selected, you can use the DATEADD function to get last year's sales while maintaining the context of the selected dates.
Total Sales Line Last Year =
ABS(
CALCULATE(
SUM(RetailTransactionSalesLines[NetAmount]),
DATEADD('Date'[Date], -1, YEAR)
)
)Last Year Month-to-Date (MTD)
LY MTD Sales =
ABS(
CALCULATE(
SUM(RetailTransactionSalesLines[NetAmount]),
DATESMTD(DATEADD('Date'[Date], -1, YEAR))
)
)Last Year Year-to-Date (YTD)
LY YTD Sales =
ABS(
CALCULATE(
SUM(RetailTransactionSalesLines[NetAmount]),
DATESYTD(DATEADD('Date'[Date], -1, YEAR))
)
)Your Kudos/Likes are much appreciated!
If this post helps, please consider Accepting it as the solution to help the other members find it more quickly.
Regards,
Kedar Pande
www.linkedin.com/in/kedar-pande - Anonymous1 year ago
Thank you DataNinja777 , dharmendars007 and Kedar_Pande ,Your insights are very good. Here are some additional points.
Hi, Thalbish
I think you can refer to the daxpatterns article related to dates, which describes in detail how to use the date table to calculate MTD, YTD, PMTD, PYTD:
Week-related calculations – DAX Patterns
MTD:
YTD:
PYTD:
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello Thalbish
Please give a try on the below measure...
Total Sales Line Last Year =
CALCULATE(
SUM(RetailTransactionSalesLines[NetAmount]),
FILTER(
ALL('Date'),
'Date'[Date] >= DATEADD(MIN('Date'[Date]), -1, YEAR) &&
'Date'[Date] <= DATEADD(MAX('Date'[Date]), -1, YEAR)))
If you find this helpful , please mark it as solution which will be helpful for others and Your Kudos/Likes 👍 are much appreciated!
Thank You
Dharmendar S
Its giving error,
The first argument to 'DATEADD' must specify a column.