Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
TomThys
Frequent Visitor

sales per yaer vs sales YTD

Hi i'm, using a sales report with an overview of the last 5 years.

to have the numbers i'm using this :

sales current year = CALCULATE([Totale sales],'Boekjaar'[Calendar Year] = YEAR(TODAY()))
sales previous year = CALCULATE([Totale sales],'Boekjaar'[Calendar Year] = YEAR(TODAY()) -1)
sales -2 = CALCULATE([Totale sales],'Boekjaar'[Calendar Year] = YEAR(TODAY()) -2)
...
 
Now i want to have the same for YTD. This because when i'm looking to the report today you are only able to compare month that are complete. for example december will not be comparable at this time.
 
thanks for the help
1 ACCEPTED SOLUTION

Pls try again

CurrentYear = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales], DATESBETWEEN('Calendar'[Date],_StartDate,_EndDate))
-----
Last 1 Year = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN('Calendar'[Date],_StartDate,_EndDate)),-1,YEAR)
---------
Last 2 Year = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN('Calendar'[Date],_StartDate,_EndDate)),-2,YEAR)

 

View solution in original post

6 REPLIES 6
Ahmedx
Super User
Super User

pls try this

 

CurrentYear = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales], DATESBETWEEN(('Calendar'[Date],_StartDate,_EndDate))
-----
Last 1 Year = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN(('Calendar'[Date],_StartDate,_EndDate)),-1,YEAR))
---------
Last 2 Year = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN(('Calendar'[Date],_StartDate,_EndDate)),-2,YEAR))

 

Sorry, I edited the measure, check it again

CurrentYear = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales], DATESBETWEEN(('Calendar'[Date],_StartDate,_EndDate))
-----
Last 1 Year = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN(('Calendar'[Date],_StartDate,_EndDate)),-1,YEAR))
---------
Last 2 Year = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN(('Calendar'[Date],_StartDate,_EndDate)),-2,YEAR))

Probably a noob question but i'm getting:

 

Operator or expression '()' is not supported in this context.

Last 1 Year YTD = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN((Boekjaar[Calendar Year],_StartDate,_EndDate)),-1,YEAR))



Pls try again

CurrentYear = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales], DATESBETWEEN('Calendar'[Date],_StartDate,_EndDate))
-----
Last 1 Year = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN('Calendar'[Date],_StartDate,_EndDate)),-1,YEAR)
---------
Last 2 Year = 
VAR _EndDate = EOMONTH(TODAY(),-1)
VAR _StartDate = Date(YEAR(_EndDate) ,1,1)
RETURN
CALCULATE( [Totale sales],  DATEADD(DATESBETWEEN('Calendar'[Date],_StartDate,_EndDate)),-2,YEAR)

 

ok thanks for the reply, the formula is working but i'm not getting the desired result.


The result that i'm looking for will show me the sales for the same period

so i think we need to work in days.
IF today is day 320

Then the numbers for previous years should also be showing until day 320

Year 1 : total sales untill today (sum of 320 days)

Year -1 :  total sales upon same day as today (sum of 320 days of year-1)

...

Share sample pbix file to help you.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.