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
alexSPY
Helper II
Helper II

Prior year, year to date sales

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).

1 ACCEPTED SOLUTION
alexSPY
Helper II
Helper II

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.

View solution in original post

18 REPLIES 18

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.