Hi @Viol1914,
The expression has to look at the past periods to see the latest one with the rate change for the selected user.
The expression to find the “applicable rate” might be as follows.
Sum(
--the latest one month
Head(
--order months with rate change to find the latest
Order(
--filter months to identify ones with rate change
Filter(
--set of months within latest previous period having rate change
DescendantsSet(
--the latest major period with rate change
Head(
Order(
Filter(
--set of periods before
PreviousPeriods(
--find the next month so that previous periods include the current one
[Time].CurrentHierarchyMember.NextMember),
--filter previous (and current) periods to find the one with rate change
[Measures].[Hourly rate]>0
),
--arrange descending by start date
[Time].CurrentHierarchyMember.StartDate,
DESC),
--retrieve the latest period with rate change
1),
--dive into latest period with rate change to level of month
[Time].[Month]),
--identify the month with rate change
[Measures].[Hourly rate]>0),
--arrange descending by start date
[Time].CurrentHierarchyMember.StartDate,
DESC),
--retrieve the latest month with rate change
1),
--use the rate change of that month
[Measures].[Hourly rate]
)
The cost for a specific month would then be the multiplication of hours spent and the applicable rate.
Since the search for applicable rates might take some calculation resources, the applicable months should be filtered for longer periods.
The expression for finding the cost for the selected user over the selected Time period might be as follows.
Sum(
Filter(
--set of months within selected period
DescendantsSet(
[Time].CurrentMember,
[Time].[Month]),
--only months with spent hours are taken
[Measures].[Hours spent]>0),
--numeric value for sum - cost for user in month
[Measures].[Hours spent]
*
[Measures].[applicable rate]
)
Since you might as well look for the total costs of the selected team or the selection of users, you might need to iterate through the set of users.
And again, the costs should only be calculated for users with applicable hours.
The expression might then be as follows.
Sum(
--only use users that have spent hours in period
Filter(
--set of (selected) users
DescendantsSet(
[Logged by].CurrentMember,
[Logged by].[User]),
--users have logged time
[Measures].[Hours spent]>0),
--numeric value for sum - cost for user in periods
Sum(
Filter(
--months of the period
DescendantsSet(
[Time].CurrentMember,
[Time].[Month]),
--where time was logged
[Measures].[Hours spent]>0),
--the cost for user in month
[Measures].[Hours spent]
*
[Measures].[applicable rate]
)
)
Regards,
Oskars / support@eazyBI.com