March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
I am new to Power BI and needs the solution of the following scenario.
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.
Solved! Go to Solution.
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)
)
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 !!! |
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)
)
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 !!! |
@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:
hi, @asgharkhan
try below
adjust your table name
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
118 | |
73 | |
57 | |
56 | |
44 |
User | Count |
---|---|
178 | |
120 | |
82 | |
68 | |
57 |