cancel
Showing results for
Search instead for
Did you mean:
Helper I

## Previous Year Calculation -1 day

Hi!

So I'm trying to "move" alla previous year metrics one day.  For example; 2022-11-18 should be compared to 2021-11-19. I have solved it on a line by line basis but the sum of days doesn't work. I realize that it must be down to my "max"-part of the calculation but can't figure out an alternative to work.

See below example, the total takes the latest date.

Formula looks like this:

CALCULATE([Sales], FILTER(ALL('Date'[Date]), 'Date'[Date]=MAX(OrderData[OrderDate])-364))

The goal is for PY Sales to look like this:

Any ideas?

1 ACCEPTED SOLUTION
Super User

Ok, try this then:

``````PY =
SUMX (
VALUES ( Table[Date] ),
CALCULATE (
[Sales],
FILTER (
ALL ( 'Date'[Date] ),
'Date'[Date]
= MAX ( OrderData[OrderDate] ) - 364
)
)
)
``````

Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.

4 REPLIES 4
Super User

Try:

``````PY with total =
SUMX(VALUES(Table[Date]), [PY Sales])``````

Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.

Helper I

Hi! The solution works, but its' not ideal because then I need to create 2 metrics for all PY calculations.

In other words, ideally I would just have 1 metric for PY rather than having to create first the "YTD"* PY calculation and then the sum calculation of that.

*YTD = Max date being last orderdate

Super User

Ok, try this then:

``````PY =
SUMX (
VALUES ( Table[Date] ),
CALCULATE (
[Sales],
FILTER (
ALL ( 'Date'[Date] ),
'Date'[Date]
= MAX ( OrderData[OrderDate] ) - 364
)
)
)
``````

Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.

Helper I

@PaulDBrown Thank you!

## Helpful resources

Announcements

#### Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

#### Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

#### Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

#### Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors