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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ninakarsa
Helper II
Helper II

calculating daily occupany rate

Hi

 

I am trying to find away to calculate the number of occupied spaces for a given day by parking area. For example, based on the arrival and departure dates how many customers have an occupied parking spot on a given day. And then to be able to drill down to view the chart/table by parking area.

1 ACCEPTED SOLUTION

@az38 What i want to be able to see is by date the occupied spaces and to be able to drill into zone as below. And to have the total displayed. Thanking you in advance

 

final result.PNG

 

The table below shows the correct values for zone, but not for left, right. The measure used for this is: 

Measure 5 = CALCULATE(COUNTROWS(bookings), FILTER(ALL(bookings), bookings[adate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]>=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[car park area]=SELECTEDVALUE(CalendarAreasTable[car park area])) )

result1.PNG

If I use measure 8, I get the correct values for car park (left/right) but there is no value displayed for zone.

Measure 8 = CALCULATE(COUNTROWS(bookings), FILTER(ALL(bookings), bookings[adate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]>=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[car park area]=SELECTEDVALUE(CalendarAreasTable[car park area]) && bookings[car park]=SELECTEDVALUE(CalendarAreasTable[car park]) ) )
result2.PNG

 

 

View solution in original post

18 REPLIES 18
az38
Community Champion
Community Champion

Hi @ninakarsa 

Your question is very complex and, obviously, there is not enough source data to give you a full and complex answer. but i try

first, the best practice is to create Calendar table for your task.

you could do this by create a calculated table like this

 

CalendarTable = CALENDARAUTO()

 

or

 

CalendarTable = CALENDAR (DATE (2019, 1, 1), DATE (2019, 12, 31))

 

next, you can create a dimension table 'Parking Areas' which define all reported areas (one area = one row in the table).

 

next, you can create a table CalendarAreasTable that will be looked like

DateParking Area
01.01.2019Zone A
01.01.2019Zone B
01.01.2019Zone C
02.01.2019Zone A
02.01.2019Zone B
02.01.2019Zone C
03.01.2019Zone A
03.01.2019Zone B
03.01.2019Zone C

to do that create a new calculated table

 

CalendarAreasTable = CROSSJOIN(CalendarTable;'Parking Areas')

 

next you can add a simple measure to your new CalendarAreasTable:

 

Measure = 
CALCULATE(COUNTROWS('DataTable'),
FILTER(ALL('DataTable'), 'DataTable'[Departure Date]<=SELECTEDVALUE('CalendarAreasTable'[Date]) && 'DataTable'[Departure Date]>=SELECTEDVALUE('CalendarAreasTable'[Date]) && 'DataTable'[Parking Area]=SELECTEDVALUE('CalendarAreasTable'[Parking Area]))
)

 

where 'DataTable' is a table with log of your parking records

So, this measure will give you quantity of customers for each day by each Area and you could drill down it easily

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Thanks for your quick response, so I will attached below the tables I have and what i want to do:

 

So Table A has the booking information, table b has the info that i want to drill by and table c is the calender

 

 

Table A: Bookings

Customer IDadateddatecar parkcar park area
12301/05/201905/05/2019LeftZone A
12402/05/201904/05/2019rightZone B
12503/05/201905/05/2019LeftZone C
12604/05/201906/05/2019rightZone A
12701/05/201903/05/2019LeftZone B
12802/05/201904/05/2019LeftZone C
12903/05/201905/05/2019LeftZone A
13001/05/201903/05/2019LeftZone B
13102/05/201904/05/2019LeftZone C
13203/05/201905/05/2019LeftZone A
13301/05/201903/05/2019LeftZone B
13402/05/201904/05/2019LeftZone A
13503/05/201905/05/2019rightZone B
13605/05/201907/05/2019rightZone C
13706/05/201908/05/2019rightZone A
13804/05/201906/05/2019rightZone A
13905/05/201907/05/2019leftZone B
14006/05/201908/05/2019leftZone C
14108/05/201910/05/2019leftZone A
14209/05/201911/05/2019leftZone B
14307/05/201909/05/2019leftZone C
14408/05/201910/05/2019leftZone A
14509/05/201911/05/2019leftZone B
14611/05/201913/05/2019leftZone C
14712/05/201914/05/2019leftZone A
14810/05/201912/05/2019leftZone B
14911/05/201913/05/2019leftZone A
15012/05/201914/05/2019leftZone B

 

Table B: Info

car parkcar park area
LeftZone A
rightZone B
 Zone C

 

Table C: Calendar

 

Table 😧 

crossjoin(calendar,Info)

 

Then I use the following calcuation to give me the number of occupied spaces on a given day: but this is not returning any results

Measure =
CALCULATE(COUNTROWS(bookings),
FILTER(ALL(bookings), bookings[adate]>=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[car park area]=SELECTEDVALUE(CalendarAreasTable[car park area]))
)

 

 

 

az38
Community Champion
Community Champion

hi @ninakarsa 

it seems you're confused marks < and >

try

Measure =
CALCULATE(COUNTROWS(bookings),
FILTER(ALL(bookings), bookings[adate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]>=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[car park area]=SELECTEDVALUE(CalendarAreasTable[car park area]))
)

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 @this still does not work. I am new to powerbi, so I am not understanding the issue. datamodel.PNG

 

Thanking you in advance

 
az38
Community Champion
Community Champion

@ninakarsa 

for me it works. please, share your pbix-file

884607.png

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 how can i share my pbix file with you?

az38
Community Champion
Community Champion

@ninakarsa

use

 https://uploadfiles.io/

and link to ptivate message if data is confidential

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 

 

I have uploaded it. and here is the link https://ufile.io/gq5sanqm

 

 

@az38  this seems to be working when i create a 'table' visual but when i create a matrix visual the data displays as below. Also how do i calculate the totals for this? Is there a way to create a table in powerbi with the result shown below?

 

result.PNG

 

az38
Community Champion
Community Champion

@ninakarsa 

to display all the data in the matrix visual press "Expand" button (see below). 

and try a measure for total correct caluclation

Measure = 
CALCULATE(COUNTROWS(bookings);allexcept(Bookings;Bookings[car park area]);
FILTER(Bookings; bookings[adate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]>=SELECTEDVALUE(CalendarAreasTable[Date]) )
)

884662.png

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 What i want to be able to see is by date the occupied spaces and to be able to drill into zone as below. And to have the total displayed. Thanking you in advance

 

final result.PNG

 

The table below shows the correct values for zone, but not for left, right. The measure used for this is: 

Measure 5 = CALCULATE(COUNTROWS(bookings), FILTER(ALL(bookings), bookings[adate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]>=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[car park area]=SELECTEDVALUE(CalendarAreasTable[car park area])) )

result1.PNG

If I use measure 8, I get the correct values for car park (left/right) but there is no value displayed for zone.

Measure 8 = CALCULATE(COUNTROWS(bookings), FILTER(ALL(bookings), bookings[adate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]>=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[car park area]=SELECTEDVALUE(CalendarAreasTable[car park area]) && bookings[car park]=SELECTEDVALUE(CalendarAreasTable[car park]) ) )
result2.PNG

 

 

az38
Community Champion
Community Champion

@ninakarsa 

the same measure as i told you before

Measure = 
CALCULATE(COUNTROWS(bookings),allexcept(Bookings;Bookings[car park area]),
FILTER(Bookings, bookings[adate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]>=SELECTEDVALUE(CalendarAreasTable[Date]) )
)

 

884662.png

 

there is a pbix-file https://ufile.io/l0a2orpl

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38thank you so much for your help...this worked perfectly. I have one more question regarding joining queries in powerbi, if you can help

 

SELECT A.carpark, A.carparkarea,location, B.ARRDATE, B.DEPDATE, c.amount FROM table1 A
JOIN table2 B ON B.RESID=A.RSID
JOIN table3 C ON C.RESDETAILID=A.RSDETAILID
JOIN table4 D ON A.NAME=D.NAME

 

 

az38
Community Champion
Community Champion

Hi @ninakarsa 

what do you mean with this sql-statement?

there are 3 good options to make join in power bi:

1. Merge option in Power Query Editor mode

2. Create relationships (you've got a simple one-parameter joins, as i see)

3. Join functions in DAX https://docs.microsoft.com/en-us/dax/naturalinnerjoin-function-dax

 

and dont forget set posts with solutions as solution for future users, please 🙂

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38Hi, you have been a great help. Following, up with this, i need to calculate % occupied spaces (occupied/total spaces). The table below shows the total spaces by car park and car park area. How can I use dax to get the following result:

 

 01/05/2019  
 occupied spacestotal spacesoccupancy
Zone A1303.3%
Left11010.0%
Right 200.0%
Zone B3456.7%
Left33010.0%
Right 150.0%
Zone C   
Left   
Right   

 

 

Car ParkCar Park AreaFrom DateTo DateSpaces
Zone ALeft01/05/201920/05/2019100
Zone ARight01/05/201920/05/201950
Zone BLeft01/05/201920/05/2019320
Zone BRight01/05/201920/05/2019150
Zone ALeft01/06/201920/06/2019150
Zone ARight01/06/201920/06/201975
Zone BLeft01/06/201920/06/2019340
Zone BRight01/06/201920/06/2019150

 

 

az38
Community Champion
Community Champion

@ninakarsa 

I do not understand how do you calculate total space and how it connects with Spaces from the second table

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38 

 

so lets say we have a table with information regarding to the car park table A. Table B, is a calcuated table showing by date customers in the car park area, so for example on the 01/05/2019 1 customer was in car park zone A & left car park area, 4 customers were in car park zone B with 3 in left car park area and 1 in right car park area. And then want to combine the two tables to say that when Date from table b is between from date and to date in table A and car park and car park area from B is equal to car park and car park area from table a then return the number of spaces in table B. This should the return table C 

 

And finally to create a measure which will return results in table d

 

Table A

Car ParkCar Park AreaFrom DateTo DateSpaces
Zone ALeft01/05/201920/05/201910
Zone ARight01/05/201920/05/201920
Zone BLeft01/05/201920/05/201930
Zone BRight01/05/201920/05/201915
Zone ALeft01/06/201920/06/201915
Zone ARight01/06/201920/06/201960
Zone BLeft01/06/201920/06/201935
Zone BRight01/06/201920/06/201970

 

Table B:

DateCustomerIDCarParkCarPark Area
01/05/2019123LeftZoneA
01/05/2019127LeftZoneB
01/05/2019130LeftZoneB
01/05/2019133LeftZoneB

 

Table C:

DateCustomerIDCarParkCarPark AreaSpaces
01/05/2019123LeftZoneA10
01/05/2019127LeftZoneB30
01/05/2019130LeftZoneB30
01/05/2019133LeftZoneB30

 

table 😧

 01/05/2019  
 occupied spacestotal spacesoccupancy
Zone A1303.3%
Left11010.0%
Right 200.0%
Zone B3456.7%
Left33010.0%
Right 150.0%
Zone C   
Left   
Right   
az38
Community Champion
Community Champion

@ninakarsa 

maybe you just need to do smth like for calculate occupied places?

Measure Spaces = 
CALCULATE(SUM('Table A'[Spaces]),allexcept(Bookings;Bookings[car park area]),
FILTER(Bookings, bookings[adate]<=SELECTEDVALUE(CalendarAreasTable[Date]) && bookings[ddate]>=SELECTEDVALUE(CalendarAreasTable[Date]) )
)

then divide

occupancy = divide([Measure], [Measure Spaces])

where measure - is a measure from above solution

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors