Subtracting one day from the date

I am looking for a solution by which I can subtract one day from a date column, but only if the year is 2020. For all other years. I want the same date from the source date column.

For example, if the primary date = 2/5/2020, I want the adjusted date column to return 2/4/2020. If the primary date is 2/4/2021, I want the adjusted date to return 2/4/2021. The minus-one-day operation should only take place in the year 2020.

The dax that I wrote works, except for on the first day of the month, at which point it returns what seems like a random date near the end of that same month.

For example, on 1/1/2020, the result should be 12/31/2019. On 2/1/2020, the result should be 1/31/2020. Instead, on 1/1/2020, my result is 1/31/2020. On 2/1/2020, my result is 3/2/2020.

Here’s what I have so far, which seems about halfway where I need to be:

Date Adjusted =

var dateminus1 = DATE(YEAR(DatesPrim[Date]),MONTH(DatesPrim[Date]), DAY(DatesPrim[Date]-1) )

return

if(YEAR(DatesPrim[Date]) = 2020, dateminus1, DatesPrim[Date])

I attached an export of other results I’m getting using this dax.
example.csv (45.0 KB)

Thank you for your help!
Pete

Hi @pete.langlois

Create a calculated as below

1 Like

Thank you so much for that detailed answer @Rajesh

We hope this helped you @pete.langlois

If not, how far did you get and what kind of help you need further?

If yes, kindly mark as solution the answer that solved your query.

Hi @pete.langlois, it’s been a while since we got a response from you. In case there won’t be any activity on it in the next few days, we’ll be tagging this post as Solved.