Forum Discussion

NMC20's avatar
NMC20
Helper I
1 year ago
Solved

Percentage by group

I'm hoping to calculate a % uptake by item but there are different numbers of items available so I need the denominater to change depending on the item name. I would like this split out by time. 

 

I've managed to do the split out by time but only as a whole number. I would like this to be a % of available items. 

 

Example:

Item08:00 - 09:0009:00 - 10:0010:00 - 11:0011:00 - 12:0012:00 - 13:00
10 Door12134
4 Door11023
6 Door0025

7

 

Available:

10 Door - 10

4 Door - 23

6 Door - 12

 

So the % I would expect is below, I just don't know how to calculate it in Power BI

 

Item08:00 - 09:0009:00 - 10:0010:00 - 11:0011:00 - 12:0012:00 - 13:00
10 Door10%20%10%30%40%
4 Door4.3%4.3%0%8.7%13%
6 Door0%0%16.7%41.7%

58.3%

 

Thanks in advance!

  • Hi NMC20 

    Another Power Query solution

    let
    Source = Your_Source,
    Unpivot = Table.UnpivotOtherColumns(Source, {"Item"}, "Attribute", "Value"),
    Group = Table.Group(Unpivot, {"Item"}, {{"Data", each _, type table }, {"Sum", each List.Sum([Value]), type number }}),
    Expand = Table.ExpandTableColumn(Group, "Data", {"Attribute", "Value"}, {"Attribute", "Value"}),
    Percentage = Table.CombineColumns(Expand, {"Value", "Sum"}, each _{0}/_{1}, "Percentage"),
    #"Type %" = Table.TransformColumnTypes(Percentage,{{"Percentage", Percentage.Type}}),
    Pivot = Table.Pivot(#"Type %", List.Distinct(#"Type %"[Attribute]), "Attribute", "Percentage", List.Sum)
    in
    Pivot

    Stéphane 

  • What is the original format of your data? From what I'm gleaning, it seems like you have more of a modeling problem than anything else.

     

    For example, based on the table you provided, I would put together a model along the lines of:

     

    Tables

     

    Items

    Item
    10 Door
    4 Door
    6 Door

     

    Availability

    ItemDateAvailabile
    10 Door7/1/202510
    4 Door7/1/202523
    6 Door7/1/202512
    10 Door7/2/202513
    4 Door7/2/202522
    6 Door7/2/202510

     

    Time Slots

    Label
    00:00 - 01:00
    01:00 - 02:00
    02:00 - 03:00
    03:00 - 04:00
    04:00 - 05:00
    05:00 - 06:00
    06:00 - 07:00
    07:00 - 08:00
    08:00 - 09:00
    09:00 - 10:00
    10:00 - 11:00
    11:00 - 12:00
    12:00 - 13:00
    13:00 - 14:00
    14:00 - 15:00
    15:00 - 16:00
    16:00 - 17:00
    17:00 - 18:00
    18:00 - 19:00
    19:00 - 20:00
    20:00 - 21:00
    21:00 - 22:00
    22:00 - 23:00
    23:00 - 24:00

     

    Uptake

    ItemDateTime SlotUptake
    10 Door7/1/202508:00 - 09:001
    10 Door7/2/202508:00 - 09:001
    10 Door7/1/202509:00 - 10:002
    10 Door7/2/202509:00 - 10:002
    10 Door7/1/202510:00 - 11:001
    10 Door7/2/202510:00 - 11:001
    10 Door7/1/202511:00 - 12:003
    10 Door7/2/202511:00 - 12:003
    10 Door7/1/202512:00 - 13:004
    10 Door7/2/202512:00 - 13:004
    4 Door7/1/202508:00 - 09:001
    4 Door7/2/202508:00 - 09:001
    4 Door7/1/202509:00 - 10:001
    4 Door7/2/202509:00 - 10:001
    4 Door7/1/202510:00 - 11:000
    4 Door7/2/202510:00 - 11:000
    4 Door7/1/202511:00 - 12:002
    4 Door7/2/202511:00 - 12:002
    4 Door7/1/202512:00 - 13:003
    4 Door7/2/202512:00 - 13:003
    6 Door7/1/202508:00 - 09:000
    6 Door7/2/202508:00 - 09:000
    6 Door7/1/202509:00 - 10:000
    6 Door7/2/202509:00 - 10:000
    6 Door7/1/202510:00 - 11:002
    6 Door7/2/202510:00 - 11:002
    6 Door7/1/202511:00 - 12:005
    6 Door7/2/202511:00 - 12:005
    6 Door7/1/202512:00 - 13:007
    6 Door7/2/202512:00 - 13:007

     

    Dates

     

    Dates = 
    GENERATE(
        CALENDARAUTO(),
        ROW(
            "Year", YEAR( [Date] ),
            "MonthNo", MONTH( [Date] ),
            "Month", FORMAT( [Date], "mmm" )
        )
    )

     

     

    Model

     

     

     

    You can then use a visual matrix to get what you are after using the following measure:

     

     

    Uptake / Available % = 
        VAR _uptake = SUM( Uptake[Uptake] )
        VAR _available = SUM( Availability[Available] )
        VAR _openSlots = CALCULATE( COUNTROWS( 'Time Slots' ), 'Time Slots'[Open] )
    RETURN
        DIVIDE( _uptake, _available * _openSlots )

     

     

     

14 Replies