Forum Discussion

sangrick's avatar
sangrick
Regular Visitor
9 years ago
Solved

display calculated values for a timespan

Hello,

 

I'm new to Power BI and I'm stuck with a problem.

I have a table with calls including the fields customer, start_date and end_date

No I want to see how many call are active during a given period (line chart or similar over the period would be good)

e.g.

CustomerStart_DateEnd_Date
A27.06.2017 23:3128.06.2017 00:27
A27.06.2017 23:3128.06.2017 01:35
B27.06.2017 23:4328.06.2017 00:09
B27.06.2017 23:4528.06.2017 00:09
C27.06.2017 23:4828.06.2017 00:06
C27.06.2017 23:4828.06.2017 00:12

Should result in an image which shows

from 23:31 to 23:43 : 2
from 23:43 to 23:45 : 3
from 23:45 to 23.48 : 4
from 23:48 to 00:06 : 6
from 00:06 to 00:09 : 5
from 00:09 to 00:12 : 3
from 00:12 to 00:27 : 2
from 00:27 to 01:35 : 1

 

The time should be on X-Axis and the number on Y-Axis (If not all customers are selected they should not be included in the number)

It could be sufficient to have the calculation not for each minute, but for a small delta of 5 minutes

 

Any ideas how to achieve this?

 

My idea was to create a temporary table with calculated values for small periods

Period ABC
23:3023:352  
23:3523:402  
23:4023:4521 
23:4523:50222
23:5023:55222
23:5500:00222
00:0000:05222
00:0500:10222
00:1000:152 1
00:1500:202  
00:2000:252  
00:2500:302  
00:3000:351  
00:3500:401  
00:4000:451  
00:4500:501  
00:5000:551  
00:5501:001  
01:0001:051  
01:0501:101  
01:1001:151  
01:1501:201  
01:2001:251  
01:2501:301  
01:3001:351  
01:3501:40   
01:4001:45   

 

but I don't know how to do that :-(

I need a column for each customer (customers can change) and I need a calculation which includes fields from a differen table.

 

All I tried with calculated columns was that I can only access fields of the same table.

 

Any help would be appreciated.

 

regards

Stephanie

 

 

  • Hi sangrick,

    You idea is to create a temporary table a small delta of 5 minutes, it's hard to compare the time wiout date. For example, 28.06.2017 00:27 is bigger than 27.06.2017 23:31 obviously. But 00:27 is less than  23:31 when we use time to compare.

    So I post my solution, please follow the steps below.

    1. Create a time table including all start_time and end_time, create a new table by clicking "New Table" under Modeling on Home Page.

    TimeTable = UNION(DISTINCT('Fact'[Start_Date]),DISTINCT('Fact'[End_Date]))


    2. Order the Start_Date column Ascending(right click the head name->Ascending), add a rank column, then get the period end time using the rank.

    rank = RANKX(TimeTable,TimeTable[Start_Date],,ASC)
    
    End_Time = LOOKUPVALUE(TimeTable[Start_Date],TimeTable[rank],TimeTable[rank]+1)



    You will get the TimeTable like the screenshot.



    3. Create A,B, C calculated columns using the formulas.

    A = CALCULATE(COUNTROWS('Fact'),FILTER('Fact','Fact'[Customer]="A"&&'Fact'[Start_Date]<=TimeTable[End_Time]&&'Fact'[End_Date]>=TimeTable[End_Time]))
    
    B = CALCULATE(COUNTROWS('Fact'),FILTER('Fact','Fact'[Customer]="B"&&'Fact'[Start_Date]<=TimeTable[End_Time]&&'Fact'[End_Date]>=TimeTable[End_Time]))
    
    C = CALCULATE(COUNTROWS('Fact'),FILTER('Fact','Fact'[Customer]="C"&&'Fact'[Start_Date]<=TimeTable[End_Time]&&'Fact'[End_Date]>=TimeTable[End_Time]))


    4. Create a stacked area chart using the TimeTable, select the start_time as Axis, and display it as category. Please see the following screenshot.




    Best Regards,
    Angelia

2 Replies

  • v-huizhn-msft's avatar
    v-huizhn-msft
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi sangrick,

    You idea is to create a temporary table a small delta of 5 minutes, it's hard to compare the time wiout date. For example, 28.06.2017 00:27 is bigger than 27.06.2017 23:31 obviously. But 00:27 is less than  23:31 when we use time to compare.

    So I post my solution, please follow the steps below.

    1. Create a time table including all start_time and end_time, create a new table by clicking "New Table" under Modeling on Home Page.

    TimeTable = UNION(DISTINCT('Fact'[Start_Date]),DISTINCT('Fact'[End_Date]))


    2. Order the Start_Date column Ascending(right click the head name->Ascending), add a rank column, then get the period end time using the rank.

    rank = RANKX(TimeTable,TimeTable[Start_Date],,ASC)
    
    End_Time = LOOKUPVALUE(TimeTable[Start_Date],TimeTable[rank],TimeTable[rank]+1)



    You will get the TimeTable like the screenshot.



    3. Create A,B, C calculated columns using the formulas.

    A = CALCULATE(COUNTROWS('Fact'),FILTER('Fact','Fact'[Customer]="A"&&'Fact'[Start_Date]<=TimeTable[End_Time]&&'Fact'[End_Date]>=TimeTable[End_Time]))
    
    B = CALCULATE(COUNTROWS('Fact'),FILTER('Fact','Fact'[Customer]="B"&&'Fact'[Start_Date]<=TimeTable[End_Time]&&'Fact'[End_Date]>=TimeTable[End_Time]))
    
    C = CALCULATE(COUNTROWS('Fact'),FILTER('Fact','Fact'[Customer]="C"&&'Fact'[Start_Date]<=TimeTable[End_Time]&&'Fact'[End_Date]>=TimeTable[End_Time]))


    4. Create a stacked area chart using the TimeTable, select the start_time as Axis, and display it as category. Please see the following screenshot.




    Best Regards,
    Angelia

    • sangrick's avatar
      sangrick
      Regular Visitor

      works nearly perfect.

      Sometimes I have a timestamp in start_date and in end_date, this causes that the lookup for End_Time doesn't work.

       

      e.g with my real data I have

      Start Date; rank; End_Time

      28.09.2016 09:00:54; 30; 28.09.2016 09:00:59

      28.09.2016 09:00:59; 31;

      28.09.2016 09:00:59; 31;

      28.09.2016 09:01:01; 33; 28.09.2016 09:01:06

       

      I change the table creation to

      TimeTable = DISTINCT(UNION(DISTINCT('Fact'[Start_Date]),DISTINCT('Fact'[End_Date])))

       

      Additionally I added columns for hour and minute to drill down

      :-)

       

      many thanks