Forum Discussion

Sab's avatar
Sab
Icon for Helper V rankHelper V
5 years ago
Solved

Calculate Peak Occupancy rate

Hello,   I created a measure to caclulcate the Occupance rate, which I think is OK: Occupancy Rate = DIVIDE ( SUM ( Reservations[Occupancy (m)] ), DATEDIFF ( MIN ( Reservations[From] ), ...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Sab 

    I find the reason that your measure will return 0 when you drill down to day level in your hierachy level.

    Your code:

    Occupancy Rate = 
    DIVIDE (
        SUM ( Reservations[Occupancy (m)] ),
        DATEDIFF ( MIN ( Reservations[From] ), MAX ( Reservations[Until] ), DAY ) * 1440,
        0
    )

    We see you use DATEDIFF(Min(From),MAX(Until),DAY), when you drill down to the day level, you will calculate the day difference between Min(From) and Max(Until) in the same day.

    For example, Date = 2021/10/22, min from and min until are both in the same day as below.

    Min(From) = 2021/10/22 07:00:00 AM 

    Max(Until) =  2021/10/22 07:00:00 PM 

    DATEDIFF based on day will only return 0, instead of 0.5. This function will only return the whole number day difference.

    So your measure is SUM ( Reservations[Occupancy (m)] )/ 0. Your result is 0.

    If you want to get min difference, using minute in datediff function instead of day *1440.

    Occupancy Rate = 
    DIVIDE (
        SUM ( Reservations[Occupancy (m)] ),
        DATEDIFF ( MIN ( Reservations[From] ), MAX ( Reservations[Until] ), MINUTE ),
        0
    )

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.