Yesterday Last Year

cmcreynolds

Active Member
Joined
May 21, 2015
Messages
295
Okay, my issue here is that there are several ways to do this. We have data that comes through every day and he asked me this morning for "yesterday's totals and comparison to same day last year"

So, my first inclination was to, within PowerPivot, take TODAY()-364. which would probably give a "close enough" response. BUT, it would not be exact when we have leap years like this year.

Plus, I think he wants the report to compare (for example) 2/16/2016 with 2/16/2015. So, is this accurate:

CALCULATE(........, (filter#1) YEAR([contactdate])=YEAR(TODAY())-1, (filter#2) and this is the weird part MONTH([contactdate])=MONTH(TODAY()-1), (filter #3) DAY????([contactdate])=DAY????(TODAY()-1)))

Is it necessary to use three filters to do this? I'm not sure if I was overthinking it.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
how about this:

DayTotalPriorYear:=calculate(<measure that totals>,filter(datedim,datedim[date]=date(year(today()-1)-1,month(today()-1),day(today()-1))))

Side note - I hardly ever use today() in a data model. Almost always the calculations are based on the age of the dataset. Typically I have a measure that determines the date of the youngest data point:
LatestTransactionDate:=calculate(max(Transactions[TransDate]),all(Transactions))
Then I would use [LatestTransactionDate] in my DAX equations instead of today(). This gives consistency to your workbooks so they can be viewed/retested/audited over time.
 
Upvote 0
You might be able to simplify this request. If you are comparing data with the "same day" last year are you looking to compare actual dates (29 Feb won't exist last year so what you gonna do?) or weekdays? In my experience it would be weekdays, e.g. you wouldn't compare sales figures from Monday and Sunday just because they have the same date. So it might be prudent to just compare 52*7 days ago, rather than mess around with recreating consistent dates
 
Upvote 0
The February 29 issue is exactly what forced me into this question. We have data coming in 24/7, and it's always been that way. While I completely agree that Mondays should be compared to Mondays, this is specifically what he asked for. (*in other words, time to ignore any analyst's suggestions*)

@PentaGal - I basically used your same formula. I just get kind of nervous when I add the third filter :)

But thank you for your help! :)
 
Upvote 0
For those curious how the above formula treats a leap day:
:=date(year("2/29/2016")-1,month("2/29/2016"),day("2/29/2016"))
results: 3/1/2015
 
Upvote 0

Forum statistics

Threads
1,224,153
Messages
6,176,728
Members
452,740
Latest member
MrCY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top