Forum Discussion

ScottA's avatar
ScottA
Frequent Visitor
5 years ago
Solved

Get results from dynamically calculated tables

Hi

I’m having trouble doing this task dynamically in PowerBI.

 

My data table is a list of flights with information such as flight number, from/to, depart/arrive times.

 

Flights

Flight NumberFlight FromFlight Todep timearr time
123AKLCHC6:007:25
456BHEWLG8:008:40
789CHCAKL10:0011:25
234ZQNAKL7:008:50
567AKLWLG19:0020:10
891WLGAKL16:0017:10
226AKLCHC6:307:55
227AKLDUD11:451:30

 

I have two reference tables;

  • A list of ports where crew are based and what I want to filter on
  • A list of time buckets that I use to group up results

Base

Base
AKL
WLG
CHC
NSN
NPL
NPE
CHC

 

Time Bucket

Time BucketTime FromTime To
0000-01000:000:59
0100-02001:001:59
0200-03002:002:59
0300-04003:003:59
0400-05004:004:59
0500-06005:005:59
0600-07006:006:59
0700-08007:007:59
0800-09008:008:59
0900-10009:009:59
1000-110010:0010:59
1100-120011:0011:59
1200-130012:0012:59
1300-140013:0013:59
1400-150014:0014:59
1500-160015:0015:59
1600-170016:0016:59
1700-180017:0017:59
1800-190018:0018:59
1900-200019:0019:59
2000-210020:0020:59
2100-220021:0021:59
2200-230022:0022:59
2300-000023:0023:59

 

Essentially, for any given choice/filter on the base table, I want the flight table filtered to give only flights to or from that location. For flights from that location I want to use the departure time, for flights to that location I want to use the arrival time. From this calculated time I wish to assign which time bucket it falls in to (using Time Bucket table). I need to differentiate from vs to, and then I want to display the # of flights by time bucket and by from/to like below. Example for AKL;

 

Ultimate Goal

 

 

 

 

 

 

 

 

 

 

 

 

 

Whats happening in background

 

Flight NumberFlight FromFlight Todep timearr timeDep/Arr TimeFrom/ToTime Bucket
123AKLCHC6:007:256:00From0600-0700
456BHEWLG8:008:40   
789CHCAKL10:0011:2511:25To1100-1200
234ZQNAKL7:008:508:50To0800-0900
567AKLWLG19:0020:1019:00From1900-2000
891WLGAKL16:0017:1017:10To1700-1800
226AKLCHC6:307:556:30From0600-0700
227AKLDUD11:451:3011:45From1100-1200

 

 

The issue is I have done this using CALCULATETABLE to create a table and then graph - but obviously it only works for AKL and isn't dynamic.

 

 

What I want to achieve is have the result change dynamically when I change the filter on the base table. So if I filtered the base table for AKL, the above would be the result.

 

Conversley, if I filtered the base table for CHC, the below would happen in the background

 

Flight NumberFlight FromFlight Todep timearr timeDep/Arr TimeFrom/ToTime Bucket
123AKLCHC6:007:2507:25To0700-0800
456BHEWLG8:008:40   
789CHCAKL10:0011:2510:00From1000-1100
234ZQNAKL7:008:50   
567AKLWLG19:0020:10   
891WLGAKL16:0017:10   
226AKLCHC6:307:5507:55To0700-0800
227AKLDUD11:451:30   

 

Ultimately wanting to display a count per hour bucket and from/to.

 

I thought the path to go down would be creating 1 or multiple measures that make use of virtual tables calculating using SELECTEDVALUE on the base table, but I just can't get it to work.

 

Appreciate any help

 

Cheers

  • ScottA , Try a measure like this to related arrival time with bucket

    calculate(countx(filter(Flights, Flights[arr time] >= Min(TimeBucket[from]) && Flights[arr time] <= max(TimeBucket[to])),[Flight Number]), values(flight[Flight Number]))

     

    You might need to copies time bucket to get this for departure time

3 Replies

  • ScottA's avatar
    ScottA
    Frequent Visitor

    amitchandak 

     

    Thank you, this pointed me in the right direction. I just made a small amendment to accomplish having it dynamic depending on filter selection of base table

     

    Selected Base = SELECTEDVALUE(Base[Base])

     

    Flights From =
    VAR SelectedBase = [Selected Base]
    VAR FilteredFlightsFrom =
        CALCULATETABLE ( Flights, Flights[Flight From] = SelectedBase )
    RETURN
        CALCULATE (
            COUNTX (
                FILTER (
                    FilteredFlightsFrom,
                    Flights[dep time] >= MIN ( 'Time Bucket'[Time From] )
                        && Flights[dep time] <= MAX ( 'Time Bucket'[Time To] )
                ),
                Flights[Flight Number]
            ),
            VALUES ( Flights[Flight Number] )
        )

     

  • ScottA , Try a measure like this to related arrival time with bucket

    calculate(countx(filter(Flights, Flights[arr time] >= Min(TimeBucket[from]) && Flights[arr time] <= max(TimeBucket[to])),[Flight Number]), values(flight[Flight Number]))

     

    You might need to copies time bucket to get this for departure time