Patrick20115
New Member
- Joined
- Apr 26, 2015
- Messages
- 1
Hi,
I have two tables with property information. Both tables have effective dating (from and to date). They are related through a property dimension table (lookup table).
The first table (PropertyFact) stores the size of the properties and the occupied space. A new record is added when the property size changes, or when the occupancy changes.
The second table (PropertyStatus) stores the status of the properties.
I am interested in calculating the average occupancy. In the pivot table I need to be able to select the data range and the status. The average occupancy should only be calculated for the properties that have the selected status at the last date of the selected date range.
I came up with the following formula for the total occupied area (occupied area * number of days):
Occupied Area :=
CALCULATE (
CALCULATE (
CALCULATE (
SUMX (
PropertyFact,
IF (
VALUE ( LASTDATE ( PropertyStatus[effective_to_dt] ) )
< VALUE ( LASTDATE ( calendar[date] ) )
|| VALUE ( LASTDATE ( PropertyStatus[effective_from_dt] ) )
> VALUE ( LASTDATE ( calendar[date] ) ),
BLANK (),
(
IF (
VALUE ( PropertyFact[EFFECTIVE_TO_DT] )
<= VALUE ( LASTDATE ( calendar[date] ) ),
VALUE ( PropertyFact[EFFECTIVE_TO_DT] ),
VALUE ( LASTDATE ( calendar[date] ) )
)
- IF (
VALUE ( PropertyFact[EFFECTIVE_FROM_DT] )
>= VALUE ( FIRSTDATE ( calendar[date] ) )
&& VALUE ( PropertyFact[EFFECTIVE_FROM_DT] )
>= VALUE ( LASTDATE ( PropertyStatus[EFFECTIVE_FROM_DT] ) ),
VALUE ( PropertyFact[EFFECTIVE_FROM_DT] ),
IF (
VALUE ( FIRSTDATE ( VALUES ( calendar[date] ) ) )
>= VALUE ( LASTDATE ( PropertyStatus[EFFECTIVE_FROM_DT] ) ),
VALUE ( FIRSTDATE ( VALUES ( calendar[date] ) ) ),
VALUE ( LASTDATE ( PropertyStatus[EFFECTIVE_FROM_DT] ) )
)
)
+ 1
)
)
* PropertyFact[PU_OCCUP_NRA_MSMNT]
),
FILTER (
PropertyStatus,
VALUE ( LASTDATE ( PropertyStatus[effective_from_dt] ) )
<= VALUE ( LASTDATE ( calendar[date] ) )
&& VALUE ( LASTDATE ( PropertyStatus[effective_to_dt] ) )
>= VALUE ( LASTDATE ( calendar[date] ) )
)
),
FILTER (
PropertyFact,
VALUE ( PropertyFact[EFFECTIVE_TO_DT] )
>= VALUE ( FIRSTDATE ( VALUES ( calendar[date] ) ) )
&& VALUE ( PropertyFact[EFFECTIVE_FROM_DT] )
<= VALUE ( LASTDATE ( VALUES ( calendar[date] ) ) )
)
),
FILTER (
calendar,
VALUE ( calendar[date] )
>= VALUE ( FIRSTDATE ( PropertyStatus[EFFECTIVE_FROM_DT] ) )
)
)
In the same way I calculate the total property area. Averagee occupancy is the division of the two.
This formula works, unless I pull the time dimension in the pivot table. Let's say I select Q1 2015, but also expand the time dimension to months. The row for January then uses the status at January 31st to calculate the status. However it should always use the status at the last selected date, which in this case is March 31.
Does anyone have an idea how I can get the last selected day regardless other filters?
Thanks,
Patrick
I have two tables with property information. Both tables have effective dating (from and to date). They are related through a property dimension table (lookup table).
The first table (PropertyFact) stores the size of the properties and the occupied space. A new record is added when the property size changes, or when the occupancy changes.
The second table (PropertyStatus) stores the status of the properties.
I am interested in calculating the average occupancy. In the pivot table I need to be able to select the data range and the status. The average occupancy should only be calculated for the properties that have the selected status at the last date of the selected date range.
I came up with the following formula for the total occupied area (occupied area * number of days):
Occupied Area :=
CALCULATE (
CALCULATE (
CALCULATE (
SUMX (
PropertyFact,
IF (
VALUE ( LASTDATE ( PropertyStatus[effective_to_dt] ) )
< VALUE ( LASTDATE ( calendar[date] ) )
|| VALUE ( LASTDATE ( PropertyStatus[effective_from_dt] ) )
> VALUE ( LASTDATE ( calendar[date] ) ),
BLANK (),
(
IF (
VALUE ( PropertyFact[EFFECTIVE_TO_DT] )
<= VALUE ( LASTDATE ( calendar[date] ) ),
VALUE ( PropertyFact[EFFECTIVE_TO_DT] ),
VALUE ( LASTDATE ( calendar[date] ) )
)
- IF (
VALUE ( PropertyFact[EFFECTIVE_FROM_DT] )
>= VALUE ( FIRSTDATE ( calendar[date] ) )
&& VALUE ( PropertyFact[EFFECTIVE_FROM_DT] )
>= VALUE ( LASTDATE ( PropertyStatus[EFFECTIVE_FROM_DT] ) ),
VALUE ( PropertyFact[EFFECTIVE_FROM_DT] ),
IF (
VALUE ( FIRSTDATE ( VALUES ( calendar[date] ) ) )
>= VALUE ( LASTDATE ( PropertyStatus[EFFECTIVE_FROM_DT] ) ),
VALUE ( FIRSTDATE ( VALUES ( calendar[date] ) ) ),
VALUE ( LASTDATE ( PropertyStatus[EFFECTIVE_FROM_DT] ) )
)
)
+ 1
)
)
* PropertyFact[PU_OCCUP_NRA_MSMNT]
),
FILTER (
PropertyStatus,
VALUE ( LASTDATE ( PropertyStatus[effective_from_dt] ) )
<= VALUE ( LASTDATE ( calendar[date] ) )
&& VALUE ( LASTDATE ( PropertyStatus[effective_to_dt] ) )
>= VALUE ( LASTDATE ( calendar[date] ) )
)
),
FILTER (
PropertyFact,
VALUE ( PropertyFact[EFFECTIVE_TO_DT] )
>= VALUE ( FIRSTDATE ( VALUES ( calendar[date] ) ) )
&& VALUE ( PropertyFact[EFFECTIVE_FROM_DT] )
<= VALUE ( LASTDATE ( VALUES ( calendar[date] ) ) )
)
),
FILTER (
calendar,
VALUE ( calendar[date] )
>= VALUE ( FIRSTDATE ( PropertyStatus[EFFECTIVE_FROM_DT] ) )
)
)
In the same way I calculate the total property area. Averagee occupancy is the division of the two.
This formula works, unless I pull the time dimension in the pivot table. Let's say I select Q1 2015, but also expand the time dimension to months. The row for January then uses the status at January 31st to calculate the status. However it should always use the status at the last selected date, which in this case is March 31.
Does anyone have an idea how I can get the last selected day regardless other filters?
Thanks,
Patrick