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
Anonymous
Not applicable

Last value with condition

Hi,

I have a table and in that column, when I see 18, I need a new column to replace this value by the last value < 18. In that case, the 16 should be 16, the 18 should be 16 and the 27 should be 27. There is another column with date.

 

Thanks

Capture.JPG

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

The first part gives us the last number < 18. The formula should be like below which just replaces 16 with "lastValue".

Column = 
VAR lastValue =
    CALCULATE ( MAX ( [idSpecies] ), Table1[idSpecies] < EARLIER ( Table1[idSpecies] ) )
RETURN
    IF ( [idSpecies] = 18, lastValue, [idSpecies] )

The example in the snapshot shows the last value of 10.

 

last value.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

 

Try this formula as a calculated column.

Column =
VAR lastValue =
    CALCULATE ( MAX ( [Column1] ), Table3[Column1] < EARLIER ( Table3[Column1] ) )
RETURN
    IF ( [Column1] = 18, 16, [Column1] )

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-jiascu-msft,

Two things about that:

 

1. It works for now but sooner or later the number in that column will change, except the 18. So when I'll see the 10, I'll want the 18 become 10. The 18 should always become the last number < 18.

 

2. In that formula I don't understand the reason of the first part: 

VAR lastValue =
    CALCULATE ( MAX ( [Column1] ), Table3[Column1] < EARLIER ( Table3[Column1] ) )
RETURN

 The formula IF([Column1] = 18, 16, [Colomun1]) get the same result?

Thanks

Hi @Anonymous,

 

The first part gives us the last number < 18. The formula should be like below which just replaces 16 with "lastValue".

Column = 
VAR lastValue =
    CALCULATE ( MAX ( [idSpecies] ), Table1[idSpecies] < EARLIER ( Table1[idSpecies] ) )
RETURN
    IF ( [idSpecies] = 18, lastValue, [idSpecies] )

The example in the snapshot shows the last value of 10.

 

last value.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

So, what you want is the EARLIER function. See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...



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...

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.