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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
natasha519
Helper II
Helper II

Create Measure with LatestDate Minus 1 Year

I have a column called 'Date' and it has dates all the way till April 2021. I then created a measure called 'Latest Date' with the following formula:

LatestDate = VAR LatestDate = CALCULATE(MAX(Table[Date]), ALL(Table)) RETURN IF (MIN(Table[Date]) = LatestDate, 1,0)
 
This provides me with a 1 for April 2021 since it is the latest date. I now want to do the same thing but this time I want it to be the latest date minus 1 year, so April 2020. 
 
How can I create a measure that has a 1 for April 2021 (from LatestDate measure) and 1 for April 2020 (LatestDate - 1)?
1 ACCEPTED SOLUTION

@natasha519  do you mean this, pbix is attached

 

forTOPN = 
IF (
    'Table'[Date] = CALCULATE ( MAX ( 'Table'[Date] ), ALL ( 'Table' ) )
        || 'Table'[Date]
            = CALCULATE ( MAX ( 'Table'[Date] ), ALL ( 'Table' ) ) - 365,
    1,
    0
)

 

 

smpa01_0-1637700528336.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

5 REPLIES 5
natasha519
Helper II
Helper II

I tried this:

LastYear =
VAR LatestDate = CALCULATE(MAX(Provisional_Data[Date]), ALL(Provisional_Data))
RETURN IF (MIN(Provisional_Data[Date]) = LatestDate-365,1,0)
 
But this only gives me a 1 for April 2020. I now want a 1 in BOTH April 2020 and where the LatestDate =1 so I can use Top N
smpa01
Super User
Super User

@natasha519  can you try htis

 

Measure = 
VAR LatestDate = CALCULATE(MAX('Table'[Date]), ALL('Table')) 
VAR _x = IF (MIN('Table'[Date]) = LatestDate,LatestDate-365)
RETURN _x

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I would want a 1 in the new column, so 1 for April 2020 and then 1 for April 2021, and the rest of the values would be 0

@natasha519  do you mean this, pbix is attached

 

forTOPN = 
IF (
    'Table'[Date] = CALCULATE ( MAX ( 'Table'[Date] ), ALL ( 'Table' ) )
        || 'Table'[Date]
            = CALCULATE ( MAX ( 'Table'[Date] ), ALL ( 'Table' ) ) - 365,
    1,
    0
)

 

 

smpa01_0-1637700528336.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@natasha519 did you have a chance to look into the solution I provided?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.