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
jtma508
Regular Visitor

YTD for all prior years

I'm trying to build a report that shows annual metrics (sales, orders, etc.) going back several years.  For each prior year I would like to show the metrics not just for the complete year, but also for the same period as the current year.  So, if the current year happens to be through day 275 of the year, I'd like to show the metric values for each prior year through day 275.  I've added a day-of-year value to my Dates table and attempted to utilize that with no luck .  I've also tried the Measure:

 

YTD Prev Sales = CALCULATE([Total Sales],DATEADD(DATESYTD('Dates'[Date]),-1,Year))
 
But that only appears to give me the value for last year and only displays it on the 'Total' row.  
 
I'm at a loss.  Anyone?  Thanks!
 
1 ACCEPTED SOLUTION
jtma508
Regular Visitor

After being repeatedly thwarted by the Time-Intelligence functions I had to brute-force a solution.  Again, I added a column to my Dates table for Day-of-Year.  Inelligant although my soluion may be, it works.  Typically you'd place a +1 after the DATEDIFF call but our data posts through the previous day so it works as written:

 

YTD PS =
VAR _SOY="1/1/" & YEAR(TODAY())
VAR _DOY=DATEDIFF(_SOY,TODAY(),DAY)
VAR SPPY=
CALCULATE([Total Sales],FILTER('Dates','Dates'[DOY]<=_DOY))
RETURN
SPPY
 
 

View solution in original post

9 REPLIES 9
jtma508
Regular Visitor

After being repeatedly thwarted by the Time-Intelligence functions I had to brute-force a solution.  Again, I added a column to my Dates table for Day-of-Year.  Inelligant although my soluion may be, it works.  Typically you'd place a +1 after the DATEDIFF call but our data posts through the previous day so it works as written:

 

YTD PS =
VAR _SOY="1/1/" & YEAR(TODAY())
VAR _DOY=DATEDIFF(_SOY,TODAY(),DAY)
VAR SPPY=
CALCULATE([Total Sales],FILTER('Dates','Dates'[DOY]<=_DOY))
RETURN
SPPY
 
 
Ashish_Mathur
Super User
Super User

Hi,

If your Dates table goes only till today's date, then then measure should work

YTD Prev Sales = CALCULATE([Total Sales],SAMEPERIODLASTYEAR('Dates'[Date]))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

as I mentioned in my original post.  Although I tried DATESYTD, I've also tried SAMEPERIODLASTYEAR and again, it only gives the value for the most recent Year (doesn't go year-by-year) and displays the value in the Totals row.

 

I'll need to see your file.  Share the download link and show your expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
samdthompson
Memorable Member
Memorable Member

Hello, try something like this:

 

Sales Amount Cumulative :=

VAR LastVisibleDate = MAX ( 'Date'[Date] )

VAR FirstVisibleDate = MIN ( 'Date'[Date] )

VAR LastDateWithSales = CALCULATE ( MAX ( 'Sales'[Order Date] ))

VAR Result =

    IF ( FirstVisibleDate <= LastDateWithSales,

        CALCULATE (

            [Sales Amount],

            'Date'[Date] <= LastVisibleDate))

RETURN

    Result

 

if you put that on a chart and with year in the legend and say week number or month name in the axis you sould be all good

 
// if this is a solution please mark as such. Kudos always appreciated.

No joy.  Just gives me each year's total sales.  My Dates table is built from the Sales table so only includes dates between the date of the company's first sale and most recent sale.  

 

oh, you need a proper date table. Make one of those first.

 

DateTable=CALENDARAUTO()

 

// if this is a solution please mark as such. Kudos always appreciated.

I have a 'proper' Date table covering all dates between the company's first and most recent purchases.

@jtma508 You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.