Forum Discussion

LL_Yoor's avatar
LL_Yoor
Frequent Visitor
2 years ago
Solved

Percentage difference from category average

Hi,

 

I have a fact table that records daily hours worked by cost centre (table name = daily_hours). There are different types of hours captured; e.g., hours worked by casual staff (casual_hours in the table below) and permanent staff (permanent_hours). There is also a column for total hours (total_hours). I have calculated a measure to get the % of total hours worked by casuals (measure_percent_casual) using the DAX formula:

 

measure_percent_casual = sum(daily_hours[casual_hours])/sum(daily_hours[total_hours])

 

The table looks like this:

cost_centredatepermanent_hourscasual_hourstotal_hoursmeasure_percent_casual
121/04/20232262821.43%
122/04/20232452917.24%
221/04/2023343378.11%
222/04/2023332355.71%
321/04/2023190190.00%
322/04/2023180180.00%
421/04/2023442464.35%
422/04/2023523555.45%

 

Each cost centre is nested in a division. The fact table recording cost centre details (table name = cc_map) looks like this:

cost_centrecc_namecc_division
1AEast
2BEast
3XWest
4YWest

 

daily_hours is related to cc_map using the cost_centre field.

 

I would like to be able to calculate the percentage of casual hours (i.e., measure_percent_casual) at the division level based on the individual cost centre displayed/selected. That way I can report (for example) the percentage difference between an individual cost centre and the division average. The table below would give the sort of output I am looking for collapsing across the two days that are present in my sample data:

cost_centreaverage_measure_percent_casualdivision_averagepercent_difference
119.33%13.12%6.21%
26.91%13.12%-6.21%
30.00%2.45%-2.45%
44.90%2.45%2.45%

 

The difficulty I am having is calculating the division average based on the cost centre selected. Any advice appreciated.

  • LL_Yoor , Create a measure to calculate the average percentage of casual hours

    average_measure_percent_casual = AVERAGEX(VALUES(daily_hours[date]), [measure_percent_casual])

     

    Then 

    Create a measure to calculate the division average percentage of casual hours:

    division_average =
    CALCULATE(
    AVERAGEX(
    VALUES(daily_hours[cost_centre]),
    [average_measure_percent_casual]
    ),
    ALLEXCEPT(cc_map, cc_map[cc_division])
    )

     

    Last create a measure for percentage differnce

    percent_difference = [average_measure_percent_casual] - [division_average]

1 Reply

  • LL_Yoor , Create a measure to calculate the average percentage of casual hours

    average_measure_percent_casual = AVERAGEX(VALUES(daily_hours[date]), [measure_percent_casual])

     

    Then 

    Create a measure to calculate the division average percentage of casual hours:

    division_average =
    CALCULATE(
    AVERAGEX(
    VALUES(daily_hours[cost_centre]),
    [average_measure_percent_casual]
    ),
    ALLEXCEPT(cc_map, cc_map[cc_division])
    )

     

    Last create a measure for percentage differnce

    percent_difference = [average_measure_percent_casual] - [division_average]