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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-xuxinyi-msft
Community Support
Community Support

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. 

v-xuxinyi-msft
Community Support
Community Support

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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