Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Average occupancy by location, between two dates

Hi there, 
I have a need to calculate the average occupancy of event locations for each event.
I've tried varying combinations of 'CALCULATE', 'FILTER', 'DATESBETWEEN' and have spent a few hours trying to find a solution on this forum.


Events vary greatly in length, but a start and end date is always available. 
I have 19 locations to date, with more added regularly.

In 'Table A' I have daily reports of occupancy for each location;

DateLocationOccupancy
20/09/21Hall560
20/09/21Park1230
21/09/21Hall540
21/09/21Park

1170

 

In 'Table B' I have start and end dates for each event, and need to calculate the average occupancy in order to calculate further statistics within this table.

Start DateEnd DateLocationAvg Occupancy
20/09/2121/09/21Hall 
20/09/2121/09/21Park 

 

Any assistance the community could provide would be greatly appreciated please!

  •  

    Avg Occupancy CC =
    AVERAGEX (
    FILTER (
    TableA,
    TableA[Location] = TableB[Location]
    && TableA[Date] >= TableB[Start Date]
    && TableA[Date] <= TableB[End Date]
    ),
    TableA[Occupancy]
    )

     

     

    Link to the sample pbix file 

     

     

2 Replies

  •  

    Avg Occupancy CC =
    AVERAGEX (
    FILTER (
    TableA,
    TableA[Location] = TableB[Location]
    && TableA[Date] >= TableB[Start Date]
    && TableA[Date] <= TableB[End Date]
    ),
    TableA[Occupancy]
    )

     

     

    Link to the sample pbix file 

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you so much!
      Seeing it laid out so clearly, it makes helps my understanding of 'FILTER' a lot.
      I had tried using 'AverageX' but clearly hadn't used the 'FILTER' correctly!


      Amazing to have a solution so quickly -