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
Gaurav_Lakhotia
Helper III
Helper III

Calculate Time Occupied Over Call during an Hour

Hello Everyone,

 

I'm facing an issue in defining time slot which will give me the time occupied on call during the day.
I've two consultants, one from India and other from USA.


Data ViewData View

 

 I've time of call and the duration of call(in minutes). In very last column I've mentioned the desired time slots.
I want to calculate, on call duration %, time slot wise.

 

Desired table,

Location1 PM2 PM3 PM4 PM5 PM6 PM7 PM
India100 %75 %100 %33.33%---
USA100 %100 %83.33%100 %25 %100 %50 %

 

Here is the file with Sample Data.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Thank you for providing sample data.

 

Your desired table outcome ignores the [Date]  column - how are you planning to handle that?  One result per day? Some sort of aggregation?  What if a call runs into a new day?

Also, I don't see any time zone information in your setup. Is that intentional?

 

First step:  Create a table that has all the columns and rows you want in the output:

 

Table = CROSSJOIN(VALUES(Call_Detail[Location]),GENERATESERIES(0,23/24,1/24))
 
lbendlin_1-1616288059074.png

 


Next step: list all the calls for the selected location.

 

Calls =
var l = SELECTEDVALUE('Table'[Location])
var t = CALCULATETABLE(Call_Detail,Call_Detail[Location]=l)
return COUNTROWS(t)
 
(the return value is just for validation purposes.  We count 4 calls for India and 6 calls for USA)
 
Next step is to generate the series for the minute numbers for each call
 
Calls =
var l = SELECTEDVALUE('Table'[Location])
var t = CALCULATETABLE(Call_Detail,Call_Detail[Location]=l)
var s = ADDCOLUMNS(t,"Mins",COUNTROWS(GENERATESERIES(Call_Detail[Time]*1440,Call_Detail[Time]*1440+Call_Detail[Duration(mins)]-1,1)))
return CONCATENATEX(s,[Mins],",")

 

(again CONCATENATEX is for validation purposes)

Then we need to create a similar series for each hour bucket

 

var h = MAX('Table'[Value])
var ht = GENERATESERIES(h*1440,h*1440+59,1)

 

And lastly we can see how many of the calls' minutes fall into the selected hour bucket, using INTERSECT()

 

Calls =
var l = SELECTEDVALUE('Table'[Location])
var ht = GENERATESERIES(max('Table'[Value])*1440,max('Table'[Value])*1440+59,1)
var t = CALCULATETABLE(Call_Detail,Call_Detail[Location]=l)
var s = ADDCOLUMNS(t,"Mins",COUNTROWS(INTERSECT(ht,GENERATESERIES(Call_Detail[Time]*1440,Call_Detail[Time]*1440+Call_Detail[Duration(mins)]-1,1))))
return SUMX(s,[Mins])
 
lbendlin_2-1616291848203.png

I'll leave the percentages calculation up to you.

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Thank you for providing sample data.

 

Your desired table outcome ignores the [Date]  column - how are you planning to handle that?  One result per day? Some sort of aggregation?  What if a call runs into a new day?

Also, I don't see any time zone information in your setup. Is that intentional?

 

First step:  Create a table that has all the columns and rows you want in the output:

 

Table = CROSSJOIN(VALUES(Call_Detail[Location]),GENERATESERIES(0,23/24,1/24))
 
lbendlin_1-1616288059074.png

 


Next step: list all the calls for the selected location.

 

Calls =
var l = SELECTEDVALUE('Table'[Location])
var t = CALCULATETABLE(Call_Detail,Call_Detail[Location]=l)
return COUNTROWS(t)
 
(the return value is just for validation purposes.  We count 4 calls for India and 6 calls for USA)
 
Next step is to generate the series for the minute numbers for each call
 
Calls =
var l = SELECTEDVALUE('Table'[Location])
var t = CALCULATETABLE(Call_Detail,Call_Detail[Location]=l)
var s = ADDCOLUMNS(t,"Mins",COUNTROWS(GENERATESERIES(Call_Detail[Time]*1440,Call_Detail[Time]*1440+Call_Detail[Duration(mins)]-1,1)))
return CONCATENATEX(s,[Mins],",")

 

(again CONCATENATEX is for validation purposes)

Then we need to create a similar series for each hour bucket

 

var h = MAX('Table'[Value])
var ht = GENERATESERIES(h*1440,h*1440+59,1)

 

And lastly we can see how many of the calls' minutes fall into the selected hour bucket, using INTERSECT()

 

Calls =
var l = SELECTEDVALUE('Table'[Location])
var ht = GENERATESERIES(max('Table'[Value])*1440,max('Table'[Value])*1440+59,1)
var t = CALCULATETABLE(Call_Detail,Call_Detail[Location]=l)
var s = ADDCOLUMNS(t,"Mins",COUNTROWS(INTERSECT(ht,GENERATESERIES(Call_Detail[Time]*1440,Call_Detail[Time]*1440+Call_Detail[Duration(mins)]-1,1))))
return SUMX(s,[Mins])
 
lbendlin_2-1616291848203.png

I'll leave the percentages calculation up to you.

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.