cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Pawan
Frequent Visitor

Previous Year DAX Calculation

Hi Team

 

Please can you help me on below issue. I have created a table like below in power bi.

By default current month selection is applied and calculated CY and PY measures like below

 

CY= CALCULATE( Sum(SalesNetAmountGBP]),Date'[CurrentDayOffset]<=0)

PY = CALCULATE([CY], SAMEPERIODLASTYEAR('Date'[Date]))
 
Issue: When i have selected 2022 full year PY measure is showing data upto 2021 december 31st instead of 2021 december 5th (today). Please can you help to write DAX for  PY measure to show last year today date data dynamically .

 

Pawan_0-1670248146594.png

 

Thanks in advance

 

@v-janeyg-msft 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Pawan 

please try

PY =
CALCULATE (
[CY],
FILTER (
SAMEPERIODLASTYEAR ( 'Date'[Date] ),
FORMAT ( [Date], "MMDD" ) <= FORMAT ( TODAY (), "MMDD" )
)
)

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Pawan 

please try

PY =
CALCULATE (
[CY],
FILTER (
SAMEPERIODLASTYEAR ( 'Date'[Date] ),
FORMAT ( [Date], "MMDD" ) <= FORMAT ( TODAY (), "MMDD" )
)
)

Pawan
Frequent Visitor

Hi @tamerj1 

 

Tha above solution is working for both month and year selection.

 

Thanks

Pawan

amitchandak
Super User
Super User

@Pawan ,

 

PY = CALCULATE([CY], SAMEPERIODLASTYEAR('Date'[Date]), format([Date],"MMDD") <= format(today() ,"MMDD")  )

@amitchandak thank you for your reply. The above solution works only for complete year(2022) selection. But is breaking when we select month or quarter. The measure should be dynamic based on Date selection.

 

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

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

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

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!

MPPC 2023 PBI Carousel

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