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
707Ute
Frequent Visitor

Cumulative Sales to Date Same Period Last Year

I need to build a measure that will give me the the  Cummulative Gross Sales for the same period last year.

 

I have my Gross Sales for 2020 by using Year and Gross Sales Measure.  These Gross Sales incorporate sales for the last 303 Days (Jan 1, 2020 - Oct 29, 2020)

 

However, I dont know how to arrive at a measure that will give me Gross Sales for the first 303 Days of 2019 and that is dynamic so tomorrow the measure will update to the first 304 Days of 2019.

 

I have tried:

Last Year YTD Gross Prod Sales = CALCULATE(SUM('1-Measures and Calculations'[Gross Sales USD]),SAMEPERIODLASTYEAR(DATESYTD('Date - Transaction Date'[PK_Date])))

but it is not providing the correct result.

 

Any help would be appreciated!

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @707Ute 

 

Do you want the measure to always display the Cummulative Gross Sales until today for the previous year without needing user to select a date? If so, you could also take the following measures for some reference. I use TODAY() function to get today value automatically.

TY Gross Sales = CALCULATE(SUM('Table'[Sales]),DATESBETWEEN('Calendar'[Date],DATE(YEAR(TODAY()),1,1),TODAY()))
LY Gross Sales = 
VAR lastYear = YEAR(TODAY())-1
VAR month = MONTH(TODAY())
VAR day = DAY(TODAY())
RETURN
CALCULATE(SUM('Table'[Sales]),DATESBETWEEN('Calendar'[Date],DATE(lastYear,1,1),DATE(lastYear,month,day)))

 

Best Regards,

Community Support Team _ Jing Zhang

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

amitchandak
Super User
Super User

@707Ute , Try measure like

Last Year YTD Gross Prod Sales = CALCULATE(SUM('1-Measures and Calculations'[Gross Sales USD]),DATESYTD('Date - Transaction Date'[PK_Date],-1,year))

 

 

LYTD forced=
var _max1 =maxx('1-Measures and Calculations',[Sales date]) //or maxx(allselected('Date - Transaction Date'),'Date - Transaction Date'[PK_Date])
var _max = date(year(_max1)-1,month(_max1),day(_max1))
return
CALCULATE(SUM('1-Measures and Calculations'[Gross Sales USD]),DATESYTD(dateadd('Date - Transaction Date'[PK_Date],-1,year)),'Date - Transaction Date'[PK_Date]<=_max)

nandic
Memorable Member
Memorable Member

Hi @707Ute ,

In Power Query add new column:

YTD Criteria = if Date.DayOfYear([Date]) <= Date.DayOfYear(DateTime.LocalNow()) then 1 else 0

After that create a measure:

YTD final =
var _filterArea = filter(ALL('Date'),'Date'[YTD Criteria] = "1")
RETURN
TOTALYTD(SUM(Sales[Sales]),'Date'[Date],_filterArea)

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.