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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Antonio_Sanchez
Frequent Visitor

Help with Dax and searching last value

Hello to all from mexico.

 

I have a question trying to find some help about DAX, for a particular condition i need to figure out.

 

i have a table where i get data for last year, where is a measure that get an account for a particular day (like odometer in a car).

i need to get the previus last value about the present value (selected value), to get the average of mile between the day of the last value and the present value.

 

Date ReportMeasureSelected value dateLast Value Date?Last Value measure?
01/14/19219243701/14/19  
4/4/1922582934/4/1901/14/19219437
7/8/1923433447/8/194/4/19225893
9/12/1923590279/12/197/8/19234344
10/7/19236478210/7/199/12/192359027
12/29/19240932812/29/1910/7/192364782

 

let me do an example to explaint this

 

if a want the average of 9/12/19, i need to get the previus value from 7/8/19 and measure 2343344 to get the difference of days (9/12/19 -7/8/19) = 66 days, then get the rest of miles (2359027- 2343344)=15683. and finally divide 15683/66 to get an average per day of 238.

 

those maths are easy, but because i have several values in a year, i need to get the previus value accordin the selected value to do the maths.

 

How can i get the previus value according the selected value?

 

thanks for your help.

 

regards

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

See my article on Mean Time Between 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

See my article on Mean Time Between 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I just can say "Thank you, thank you Greg"

 

its awesome the knowledge and participation of all the comunity, i really appreciate you attention and help with this,

 

and curiusly, the post you share its a great guide for persons performing maintenance.

 

the only consideration  need to share with you, i dont have the second column to calculate measures, i mean, in your example, i dont have the RepairStarted column, only have the RepairCompleted column. that was the reason to try to find a way to get the last data value of the same column for RepairCompleted, to calculate the differences in days between the current value date and the last data value date of the same machine (in your example).

 

i tried to figure out with the example, and the "VAR next", was a great help, because i can get the next data value for the selected value 

Step 1 =
VAR next = MINX(FILTER(MTBF1,
MTBF1[MachineName] = EARLIEST(MTBF1[MachineName])
&&
MTBF1[RepairStarted] > EARLIER(MTBF1[RepairStarted])
&&
MTBF1[RepairType] <> "PM"
),MTBF1[RepairStarted])
return next
 
unfortunely not the last date, to know when was tue last date the machine failed, and get the measure of something, like "Tortillas" if you consider what your machine made.
 
again, Thanks
 
regards.

Just a good new, I find the answer to find the last value instead the next value.

 

i was checking your post several times, and  finding the MAX of the RepairStarted column after filtering our Repair table for machines that are equal to the current machine in the row as well as having a RepairStarted that is before the current.

Step =
VAR next = MAXX(FILTER(MTBF1,
MTBF1[MachineName] = EARLIER(MTBF1[MachineName])
&&
MTBF1[RepairStarted] < EARLIER(MTBF1[RepairStarted])
&&
MTBF1[RepairType] <> "PM"
),MTBF1[RepairStarted])
return next
 
is totaly appreciate your atention and guide to help understanding DAX.
 
thanks

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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