Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
asgharkhan
Frequent Visitor

Previous Year To Month

Hi, 

I am new to Power BI and needs the solution of the following scenario.

 

Screenshot 2023-10-14 191921.png

As the picture above depicts i need a DAX formula for values to be summed for same month that is for september but not of current year rather previous year's septemeber.

 

Best Regards. 

1 ACCEPTED SOLUTION
Anand24
Super User
Super User

Hi @asgharkhan ,
You can try below DAX:
1. Using -365 Days method and no specific DAX function (This will cover multiple year scenario as well if selected in date slicer)

PY_YTD = 
VAR Y =
YEAR ( CALCULATE ( MAX ( 'Calendar_Table'[Date] ) ) )
VAR a =
CALCULATE ( MIN ( 'Calendar_Table'[Date] ), 'Calendar_Table'[Year] = Y ) - 365
VAR b =
CALCULATE ( MAX ( 'Calendar_Table'[Date] ), 'Calendar_Table'[Year] = Y ) - 365
RETURN
CALCULATE (
SUM(DocAmount),
'Calendar_Table'[Date] >= a,
'Calendar_Table'[Date] <= b
)

2. Using SAMEPERIODLASTYEAR

PY_YTD = 
CALCULATE(
SUM(DocAmount),
SAMEPERIODLASTYEAR('Calendar_Table'[Date])
)

 

3. Using DATEADD

PY_YTD = 
CALCULATE(
SUM(DocAmount),
DATEADD('Calendar_Table'[Date], -1, Year)
)

 

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

View solution in original post

5 REPLIES 5
Anand24
Super User
Super User

Hi @asgharkhan ,
You can try below DAX:
1. Using -365 Days method and no specific DAX function (This will cover multiple year scenario as well if selected in date slicer)

PY_YTD = 
VAR Y =
YEAR ( CALCULATE ( MAX ( 'Calendar_Table'[Date] ) ) )
VAR a =
CALCULATE ( MIN ( 'Calendar_Table'[Date] ), 'Calendar_Table'[Year] = Y ) - 365
VAR b =
CALCULATE ( MAX ( 'Calendar_Table'[Date] ), 'Calendar_Table'[Year] = Y ) - 365
RETURN
CALCULATE (
SUM(DocAmount),
'Calendar_Table'[Date] >= a,
'Calendar_Table'[Date] <= b
)

2. Using SAMEPERIODLASTYEAR

PY_YTD = 
CALCULATE(
SUM(DocAmount),
SAMEPERIODLASTYEAR('Calendar_Table'[Date])
)

 

3. Using DATEADD

PY_YTD = 
CALCULATE(
SUM(DocAmount),
DATEADD('Calendar_Table'[Date], -1, Year)
)

 

PBI_SuperUser_Rank@1x.png  

Give a Thumbs Up if this post helped you in any way and Mark This Post as Solution if it solved your query !!!

Proud To Be a Super User !!!
LinkedIn

Greg_Deckler
Super User
Super User

@asgharkhan You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

But specifically this video has examples of various methods to do this:



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Dangar332
Super User
Super User

hi, @asgharkhan 

try below 
adjust your table name

result =
TOTALYTD(SUM('Table'[document]),'Table'[date])

Dangar332_0-1697295394635.png

 

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly. Appreciate your kudos

Thank You for the reply but unforntunatly it didn't solve  the issue. In fact I need only sum of figures of previous year (2022) but upto the month same as current month (i.e September). 

hi, @asgharkhan 

use    DATEADD  function

result = CALCULATE(SUM('Table'[document]),DATEADD('Table'[date],-1,YEAR))

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.