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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculating time difference...

Hi guys,

 

I have a dataset with the history of changes to items. Some of those items have been 'tagged' as blocked on certain dates.

Whilst I've managed to calculate the total time an item has spent blocked when the tag is removed, I'm struggling with how do I calculate how long an item that is currently tagged as blocked has been blocked for.

 

Here is an example from the dataset:

 

Calc.JPG

 

It has been tagged as blocked since 30/11/2020 08:05:31 (so roughly 2 days) - just wondering what my column/measure should be to work this out? Above my Power BI knowledge level 😞

10 REPLIES 10
Anonymous
Not applicable

Sorry for the delay, here is a link to a file with dummy data. The 'write a blog post' item has been blocked since 27th November but has had updates to it since (but still remains blocked). Thanks 🙂

Hi  @Anonymous ,

 

I cant match the data with your expected output,but checking the previous data,with the measure below,it works fine:

Measure = SUMX(VALUES('Table'[WorkItemId]),SUM('Table'[Column 2]))

v-kelly-msft_0-1607995148186.png

Would you pls explain more about how to get the result you need  based on your .pbix file?

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

Thanks, that isn't quite there yet 😞

 

Entered it in and seeing the following:

 

Calc3.JPG

 

I believe the "correct" number should be 2.23, based on NOW()-WorkItemsBlocked[ChangedDate] but using the 08:05 timestamp (as this was the first time in the current collection of 'blocked' tags it was blocked)...

Hi  @Anonymous ,

 

First split column "ChangedDate" into 3 columns as below:

v-kelly-msft_0-1607321825988.png

 

Then create a column as below:

Column 2 = 
var _datetime=IF('Table'[Status]="Blocked",CALCULATE(MAX('Table'[datetime]),FILTER('Table','Table'[WorkItemId]=EARLIER('Table'[WorkItemId])&&'Table'[Status]="Blocked"&&'Table'[Index]<EARLIER('Table'[Index]))),BLANK())
var _time=CALCULATE(MAX('Table'[Time]),FILTER('Table','Table'[datetime]=_datetime))
var _date=CALCULATE(MAX('Table'[ChangedDate.1]),FILTER('Table','Table'[datetime]=_datetime))
var _previousstatus=CALCULATE(MAX('Table'[Status]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1&&'Table'[WorkItemId]=EARLIER('Table'[WorkItemId])))
Return
IF('Table'[Status]="Blocked"&&_date<>BLANK()&&_previousstatus="Blocked",
IF(DATEDIFF(_date,'Table'[ChangedDate.1],DAY)=0,
DATEDIFF(_time,'Table'[Time],HOUR)/24,
DATEDIFF(_date,'Table'[ChangedDate.1],DAY)-(24-(HOUR('Table'[Time])+MINUTE('Table'[Time])/60))/24)
)

And you will see:

v-kelly-msft_1-1607321888112.png

 

 

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Anonymous
Not applicable

Thanks @v-kelly-msft - that has gotten me there 🙂

 

Capture7.JPG

Only issue is my bar chart still wants to sum the above values:

 

Capture8.JPG

 

Any way around this?

Hi @Anonymous ,

 

Create a measure as below:

Measure = SUMX(ALL('Table'),'Table'[Column 2])

And you will see:

v-kelly-msft_0-1607392045759.png

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

 

Anonymous
Not applicable

Thanks - unfortunately that doesn't seem to work, and is summing for all the items in that table (there are multiple different work item ID's)...any ideas?

Hi @Anonymous ,

 

If it's not convinient to provide your data,would you pls make a more detailed sample data for me to test?

 

Or you may try use below measure :

Measure=SUMX(ALLSELECTED('TABLE'[Client Azure DevOps]),'Table'[Column 2])

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Hi @Anonymous ,

 

Could you pls upload your .pbix file to onedrive business and share the link with us?Remember to remove the confidential information.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

amitchandak
Super User
Super User

@Anonymous , Create a new column like and try

new column =
datediff(maxx(filter(table, [workitemid] = earlier([workitemid]) && [index] = earlier([index]) -1 && [Tagname] =earlier([Tagname]) && [Tagname] ="Blocked"),[ChangedDate]),[ChangedDate] ,minute)/60*24

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.