Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Measure using different tables and multiple dynamic filters

Hello PowerBI community, could you please help me with the following question?

 

I have these two tables that I want to filter using the Service Hour that I choose, for example, I'm interessed in the service hours between 7h and 9h. Then, I need to calculate how many passengers were transported divided by vehicle hours, considering only the hours I filtered.

 

These are the tables :

Shift IDStartEndShift total hoursService Hours
106:0012:0006:0002:00
206:3009:0002:3002:00
306:0008:3002:3001:30
407:0012:0005:0002:00
507:0011:0004:0002:00
608:0010:0002:0001:00

 

 

Booking IDPaxPickup timeShift IDService pax
1106:0010
2107:0021
3207:3022
4208:3032
5508:4535
6109:0041
7209:0140
8110:0040

 

 

So I created the calculated columns Service Hours and Service pax, to calculate the hours each vehicle worked and how many passengers travelled in the hours I want to filter.

 

But the thing is that I don't know how to do that using dynamic filters, where the user can choose the hours he wants to filter and that will change the calculations and give a new result. Can someone help me with that please?

 

So in this case I would have 11 passengers divided by 10,5 vehicle hours, so 1,047619 as a result.

 

I know that I can't use HASONEVALUE in calculated columns but any ideas on how to do that? I'm stucked at the moment :(

2 Replies

  • v-yuta-msft's avatar
    v-yuta-msft
    Icon for Community Support rankCommunity Support

    Hi lucas_pbi,

     

    To achieve dynamic filter as you mentioned, you should use measure instead of calculate column like pattern below:

     

    Amount =
    CALCULATE (
        DISTINCTCOUNT ( Table[Shift ID] ),
        ALLSELECTED ( Table[Services hours] )
    )
    

    Regards,

    Jimmy Tao

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello,

       

      With this measure I can count the different shifts but how can I calculate how many hours for each shift between 7h and 9h for example?

       

      Thanks,