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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ericsara
Helper I
Helper I

Sum days based on status

Hello, wonderful world of Power BI. Hoping you can help me with this one. 

We have a ticketing system where a ticket can move from one status to another. As it does, the date it moved is recorded. Thus for a single ticket, we can get a table of data like this. 

 

DateStatus
2/05/2022Open
4/05/2022Support
8/05/2022Admin
8/05/2022Support
24/05/2022Development
29/05/2022Support
31/05/2022Development
7/06/2022Support
10/06/2022Closed

 

I want to calculate the total days the ticket has been on any given status.

So, for example, if I wanted to see how many days it has been on the status of Development, then it would be the day's difference between 24/5/00 to 29/5/22 (5 Days) + the difference between 31/05/22 to 7/6/22 (6 Days).

So the result I am looking for is 11 Days. 

 

Any ideas on how I can do this?

 

Cheers, 

 

 

3 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@ericsara , a new column

datediff([Date], minx(filter(table, [Date] > earlier([Date]) ),[Date]),day)

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

View solution in original post

ddpl
Solution Sage
Solution Sage

@ericsara 

 

In your instance for development "24/5/00 to 29/5/22 (5 Days) + the difference between 31/05/22 to 7/6/22 (7 Days)." in which total  is 12 days not 11.

 

@amitchandak 

 

In your solution you missed the duplicate date scenario , Admin and support both got on same date 08/05/2022.

 

The improved calculated column is shown below:

 

First add index column start from 1 in power query

 

Then 

 

Column =
DATEDIFF (
'Table'[Date],
MINX (
FILTER (
'Table',
'Table'[Date] >= EARLIER ( 'Table'[Date] )
&& 'Table'[Index] > EARLIER ( 'Table'[Index] )
),
'Table'[Date]
),
DAY
)

 

View solution in original post

@ericsara try this

 

Column =
DATEDIFF (
'Table'[Date],
MINX (
FILTER (
'Table',
'Table'[Date] >= EARLIER ( 'Table'[Date] )
&& 'Table'[Index] > EARLIER ( 'Table'[Index] )
&& 'Table'[Ticket no] = EARLIER ( 'Table'[Ticket no] )
),
'Table'[Date]
),
DAY
)

 

View solution in original post

5 REPLIES 5
v-yalanwu-msft
Community Support
Community Support

Hi, @ericsara ;

You could create a measure :

Development = 
 var _max= CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),[Ticket]=MAX('Table'[Ticket])&&[Status]="Development"))
 var _min= CALCULATE(MIN('Table'[Date]),FILTER(ALL('Table'),[Ticket]=MAX('Table'[Ticket])&&[Status]="Development"))
 return DATEDIFF(_min, CALCULATE(MAX('Table'[Date]),FILTER('Table',[Ticket]=MAX('Table'[Ticket])&&[Date]>=_min&& [Date]<=_max)),DAY)
sum = SUMX(SUMMARIZE(FILTER(ALL('Table'),[Ticket]=MAX('Table'[Ticket])),[Date],[Status],"1",[Development]),[1])

The final show:

vyalanwumsft_0-1659425070466.png


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

ericsara
Helper I
Helper I

Thanks @ddpl and @amitchandak 

I have been playing with this and wonder if you would expect it to still work with a data set such as this. 

DateStatusTicket
2/05/2022Open1
4/05/2022Support1
8/05/2022Admin1
8/05/2022Support1
24/05/2022Development1
29/05/2022Support1
31/05/2022Development1
7/06/2022Support1
10/06/2022Closed1
2/05/2022Open2
5/05/2022Support2
8/05/2022Admin2
8/05/2022Support2
24/05/2022Development2
29/05/2022Support2
2/06/2022Development2
10/06/2022Closed2

 

In this example I want the number of days between statuses to be realted to the ticket number. 

@ericsara try this

 

Column =
DATEDIFF (
'Table'[Date],
MINX (
FILTER (
'Table',
'Table'[Date] >= EARLIER ( 'Table'[Date] )
&& 'Table'[Index] > EARLIER ( 'Table'[Index] )
&& 'Table'[Ticket no] = EARLIER ( 'Table'[Ticket no] )
),
'Table'[Date]
),
DAY
)

 

ddpl
Solution Sage
Solution Sage

@ericsara 

 

In your instance for development "24/5/00 to 29/5/22 (5 Days) + the difference between 31/05/22 to 7/6/22 (7 Days)." in which total  is 12 days not 11.

 

@amitchandak 

 

In your solution you missed the duplicate date scenario , Admin and support both got on same date 08/05/2022.

 

The improved calculated column is shown below:

 

First add index column start from 1 in power query

 

Then 

 

Column =
DATEDIFF (
'Table'[Date],
MINX (
FILTER (
'Table',
'Table'[Date] >= EARLIER ( 'Table'[Date] )
&& 'Table'[Index] > EARLIER ( 'Table'[Index] )
),
'Table'[Date]
),
DAY
)

 

amitchandak
Super User
Super User

@ericsara , a new column

datediff([Date], minx(filter(table, [Date] > earlier([Date]) ),[Date]),day)

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Solution Authors
Top Kudoed Authors