Forum Discussion
Ikigai
1 year agoNew Member
DATEADD function (DAX) for previous year by slicer
I have a dataset that starts in July 2023 and updates each month. Lastest refresh is up to November 2024. December 2024 is still needing to come in. I am using the DATEADD measure to look at previ...
- 1 year ago
Hi Ikigai
Please try this:
PreviousYear2 = VAR FullYear = CALCULATE ( [Total Revenue], FILTER ( ALL ( Dates ), Dates[Year] = MAX ( Dates[Year] ) - 1 ) ) VAR LastYear = CALCULATE ( [Total Revenue], DATEADD ( Dates[Date], -1, YEAR ) ) VAR MonthSelectedTest = --test if allselected months less than all months COUNTROWS ( ALLSELECTED ( Dates[Month Short] ) ) < COUNTROWS ( ALL ( Dates[Month Short] ) ) RETURN --will return the full last year if year if no period is selected IF ( MonthSelectedTest, LastYear, FullYear )Attached is a sample pbix
danextian
Super User
1 year agoHi Ikigai
Please try this:
PreviousYear2 =
VAR FullYear =
CALCULATE (
[Total Revenue],
FILTER ( ALL ( Dates ), Dates[Year] = MAX ( Dates[Year] ) - 1 )
)
VAR LastYear =
CALCULATE ( [Total Revenue], DATEADD ( Dates[Date], -1, YEAR ) )
VAR MonthSelectedTest =
--test if allselected months less than all months
COUNTROWS ( ALLSELECTED ( Dates[Month Short] ) ) < COUNTROWS ( ALL ( Dates[Month Short] ) )
RETURN
--will return the full last year if year if no period is selected
IF ( MonthSelectedTest, LastYear, FullYear )
Attached is a sample pbix
- Ikigai1 year agoNew Member
Thank you so much, danextian!
This worked perfectly. I appreciate your help and assistance.