Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Occupance by datetime

Hi all,

 

I am trying to create a calculation based on the amount of persons that are in a room based on two datetime field. I have a date table and another table that looks like this:

IDInOutdateFrom dateToEnd of Hour
1508/18/2020 10:00:00 AM8/18/2020 10:15:00 AM11
21078/18/2020 10:15:00 AM8/18/2020 10:30:00 AM11
35108/18/2020 10:30:00 AM8/18/2020 10:45:00 AM11
442408/18/2020 10:45:00 AM8/18/2020 11:00:00 AM12
523288/18/2020 11:00:00 AM8/18/2020 11:15:00 AM12


I already created 2 simple measure to calculate the total In and Out with a SUM(). With the third measure I am trying to calculate the difference between them. I now have a simple subtraction of both measure.

When I throw this measure into an table, combine this with the date of my date table and the End of Hour column, created in Power Query, I only get to see the difference between the hours. But I also need to see in the next hour how many persons there are still in the room of the last hour. This makes sense because in my calculation I do not take the dateFrom and dateTo columns.

 

My question is, I know that I have to use them to calculate the exact difference between these columns and also to remember the amount of persons of the last hour. Only I do not know how I can take these columns into the measure. I would like to create the following table:

 

IDInOutdateFrom dateToEnd of HourOccupancy
1508/18/2020 10:00:00 AM8/18/2020 10:15:00 AM115
21078/18/2020 10:15:00 AM8/18/2020 10:30:00 AM118
35108/18/2020 10:30:00 AM8/18/2020 10:45:00 AM113
442408/18/2020 10:45:00 AM8/18/2020 11:00:00 AM125
523288/18/2020 11:00:00 AM8/18/2020 11:15:00 AM120

 

Thank you in advance

  • lbendlin's avatar
    lbendlin
    6 years ago

    When you create measures you have to think about filter context and the type of visual you want to use. A good measure works in one scenario. A great measure works in multiple scenarios, including Totals.

8 Replies

  • Anonymous 

    Not clear on the exact question, can you explain more on the requirement?

    ________________________

    Did I answer your question? Mark this post as a solution, this will help others!.

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube, LinkedIn

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Fowmy , thank you for your reply.

       

      I would like to calculate the occupancy of a room based on the hour on a daily basis. I have created an image, where I have put the dataset in it that I have and the table that I want to create, with the hope that my question become a little bit more clearly.

       


      My goal is to calculate the difference of the IN and OUT numbers, based on the datetime so I can create a line graph with it or an Matrix.

      With this Image, is my question a little bit more clearly? Otherwise, please explain what part you don't understand and therefor I can try to explain that part a bit more. Sorry, but my english is not really good. 

  •  

    Occupancy := 
    var i = max(Occupancy[ID])
    return CALCULATE(sum(Occupancy[In])-sum(Occupancy[Out]),allselected(Occupancy),Occupancy[ID]<=i)

     

    or for the CalcuHaters:

     

    Occupancy  := sumx(FILTER(allselected(Occupancy),Occupancy[ID]<=max(Occupancy[ID])),Occupancy[In]-Occupancy[Out])