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
Anonymous
Not applicable

Most Recent Year Sales with Dynamic Dates

Looking to calculate sales growth, by product, over a filterable period of time (using a date slicer), by calculating total sales for the most recent year of the period, sales for the first year of the period, and then calculating the percentage difference between the two.

 

Currently using the following measures:

 

Last Year Sales = CALCULATE(SUM('Order Index'[Sales]),DATESBETWEEN('Order Index'[Date],DATEADD(LASTDATE('Order Index'[Date]),-364,DAY),LASTDATE('Order Index'[Date])))
 
First Year Sales = CALCULATE(SUM('Order Index'[Sales]),DATESBETWEEN('Order Index'[Date],FIRSTDATE('Order Index'[Date]),DATEADD(FIRSTDATE('Order Index'[Date]),364,DAY)))
 
Sales Growth = ([Last Year Sales]/[First Year Sales])-1
 
The First Year Sales formula is producing results that are either correct, or close to correct but not quite
 
The Last Year Sales formula is having varying results by product. Some prodcuts are returning perfectly correct results. Others are returning nearly correct results. And others are returning the grand total for sales (over a the 5 year life of the dataset) rather than just the most recent year.
 
Looking for help. Thanks.
1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please create a CALENDAR table with no relationship between fact table and use it's date column as slicer

 

CALENDAR = CALENDARAUTO()

 

Below are the measures i made that according to you description and the result would be shown as below.

 

First Year Sales = CALCULATE(SUM('Table'[sales]),DATESBETWEEN('Table'[date],MIN('CALENDAR'[Date]),EDATE(MIN('CALENDAR'[Date]),12)))

Last Year Sales = CALCULATE(SUM('Table'[sales]),DATESBETWEEN('Table'[date],EDATE(MAX('CALENDAR'[Date]),-12),MAX('CALENDAR'[Date])))

Sales Growth = ([Last Year Sales]/[First Year Sales])-1

 

1.PNG2.PNG

Pbix as attached.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

2 REPLIES 2
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please create a CALENDAR table with no relationship between fact table and use it's date column as slicer

 

CALENDAR = CALENDARAUTO()

 

Below are the measures i made that according to you description and the result would be shown as below.

 

First Year Sales = CALCULATE(SUM('Table'[sales]),DATESBETWEEN('Table'[date],MIN('CALENDAR'[Date]),EDATE(MIN('CALENDAR'[Date]),12)))

Last Year Sales = CALCULATE(SUM('Table'[sales]),DATESBETWEEN('Table'[date],EDATE(MAX('CALENDAR'[Date]),-12),MAX('CALENDAR'[Date])))

Sales Growth = ([Last Year Sales]/[First Year Sales])-1

 

1.PNG2.PNG

Pbix as attached.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

create a date table and use that

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

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.