cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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 .

1 ACCEPTED SOLUTION
Super User

Hi @Pawan

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

4 REPLIES 4
Super User

Hi @Pawan

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

Frequent Visitor

Hi @tamerj1

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

Thanks

Pawan

Super User

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

Frequent Visitor

@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.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

#### Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors