Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

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

1 ACCEPTED SOLUTION

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.

View solution in original post

8 REPLIES 8
lbendlin
Super User
Super User

 

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])

 

Anonymous
Not applicable

Hi @lbendlin ,


I don't need to filter on the ID, I use a slicer for this. I need to filter on de time, please take a look at my picture that I have posted in the previous post. I want to recreate the right table, in the image, with the data that is on the left. 

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.

Anonymous
Not applicable

Thank you, I have managed to create the table that I would like to have with a filter. Stupid of me to not think about that.

@lbendlin 

 

Please define CalcuHater.

I'm pretty sure I need this word in my life but must understand the etymology  😄

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Fowmy
Super User
Super User

@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

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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.

 

power-bi-occupancy-help.png


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. 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors