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.
It seems that many people are struggling to accomplish this. I'm trying to show a comparison in a table with this year's sales, and last year over the same time. This year is simple, but last year is proving to be difficult because my sales table doesn't have continguous dates, so I can't use SAMEPERIODLASTYEAR.
I have created the following calcualtion which correctly shows the total in the previous year through the current month, but shows the entire month, not to-date:
PY YTD Net Sales =
CALCULATE(
SUM(Sales[NET SALES]),
FILTER(
ALL('Date2'),
Date2[YEAR] = (YEAR(NOW())-1)
&& Date2[MONTH NUMBER] <= MONTH(NOW())
&& Date2[DAY] <= MAX(Sales[Day])
)
)
As you can see, I have a table created with continguous dates, 'date2', and have a relationship establish between this table, and my sales table (one to many relationship).
Solved! Go to Solution.
I was able to build a solution using the following measure:
PY YTD Net Sales =
CALCULATE(
SUM(Sales[NET SALES]),
SAMEPERIODLASTYEAR(
DATESYTD(Date2[Date])
),
FILTER(
ALL(Date2),
Date2[MONTH NUMBER] <= (MONTH(NOW())-1)
)
)+
CALCULATE(
SUM(Sales[NET SALES]),
SAMEPERIODLASTYEAR(
DATESYTD(Date2[Date])
),
FILTER(
ALL(Date2),
Date2[MONTH NUMBER] = MONTH(NOW())
&& Date2[DAY] <= DAY(NOW())
)
)
The key was adding in the current month as a separate function. Without this, I was getting the sum of an entire months sales in the current month for the previous year.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
94 | |
77 | |
65 | |
53 |
User | Count |
---|---|
145 | |
105 | |
104 | |
90 | |
63 |