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
Aurick
New Member

Calculate the number of days an item was in a particular status based on different columns

I've only recently started learning Power BI and I'm trying to figure out how to show the age of an a particular ID as the status changes.  Below is an example of how the data is set up.   I'm trying to come up with a DAX that will look match up the new value to the prior value, and then give me the difference in days.  So for example, ID 1 was created on 2/1 with a brand new value of "new" and then someone looked at it and updated it on 2/2, so that would be 1 day.  

 

I'm getting caught up in how I get it to find that same ID number based on the new value to the Prior value. Any guidance would be appreciated! Thank you! 

 

IDEditedPrior Value

New_vaule

12/1/2024 

New

12/2/2024New

In Review

12/4/2024In Review

Approval

12/6/2024Approval

Completed

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Aurick 

 

You can create a calculated column as follows.

datediff = 
VAR _prior = CALCULATE(MAX([Edited]), FILTER('Table', [Edited] <= EARLIER('Table'[Edited]) && [New_vaule] = EARLIER('Table'[Prior Value]) && [ID] = EARLIER('Table'[ID])))
RETURN
DATEDIFF(_prior, [Edited], DAY)

 

vxuxinyimsft_0-1707728686705.png

Is this the result you expect?

 

Best Regards,
Yulia Xu

 

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

5 REPLIES 5
Aurick
New Member

Thank you all for your help. 

Anonymous
Not applicable

Hi @Aurick 

 

You can create a calculated column as follows.

datediff = 
VAR _prior = CALCULATE(MAX([Edited]), FILTER('Table', [Edited] <= EARLIER('Table'[Edited]) && [New_vaule] = EARLIER('Table'[Prior Value]) && [ID] = EARLIER('Table'[ID])))
RETURN
DATEDIFF(_prior, [Edited], DAY)

 

vxuxinyimsft_0-1707728686705.png

Is this the result you expect?

 

Best Regards,
Yulia Xu

 

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

Aurick
New Member

I think it's getting me there, I should have mentioned that I"m using May 2022 version (company choice) and when I try to enter what you provided in "Offset" isn't showing as a function

 

@Aurick 

output

 

Daniel29195_0-1707506857654.png

 

 

calculated column

Column 2 = 
var ids = 'Table'[ID]
var current_date =  'Table'[Edited]
var ds = 
FILTER(
    'Table',
    'Table'[ID] = ids && 'Table'[Edited] <current_date
)

var prev_date  = 
SELECTCOLUMNS(
    TOPN(
        1,
        ds,
        'Table'[Edited],
        DESC
    ),
    'Table'[Edited]
)

var res =  DATEDIFF(prev_date, current_date , DAY)

return res

 

 

 

let me know if this works for you .

 

 

 

if it does, please mark as accepted solution, so you can help others to find it more easily. 

Daniel29195
Super User
Super User

@Aurick 

 

sample data : 

Daniel29195_0-1707501659645.png

 

 

calculated column : 

Column = 
var current_date =  'Table'[Edited]
var prev_date = 
SELECTCOLUMNS(
OFFSET(
    -1,
    SUMMARIZE(
        'Table',
        'Table'[ID],
        'Table'[Edited]
    ),
    ORDERBY('Table'[Edited], ASC),
    PARTITIONBY('Table'[ID])
),'Table'[Edited])
return DATEDIFF(prev_date , current_date ,DAY)

 

 

 

let me know if this works for you .

 

 

 

if it does, please mark as accepted solution, so you can help others to find it more easily. 

 

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.