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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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