Forum Discussion

Jarrod's avatar
Jarrod
Helper III
2 years ago
Solved

Measure To Calculate Cumulative Percentage

Hi,

 

I am trying to create a graph that displays total hours per item, and then display a cumulative percentage as a line graph. Example from Excel attached.

 

 

 

Dataset: Cumulative % is not in the dataset. It is just a calculation I have done in Excel for example.

PersonHoursCumulative %
A6060%
B2585%
C15100%

 

Dataset below is an example dataset similar to mine. I would like this graph to be able to drill up to the Team, while also drilling down to the reason. There are also other filters affecting this visual such as date.

 

TeamPersonReasonHours
1ACleaning20
1ACleaning10
1AServing30
2BServing20
2BCleaning5
1CCleaning15

 

Any assistance would be appreciated.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Jarrod,

    You can add an index field on query edit side based on person group, then you can write a more formula to calculate the cumulative percent based on current index.

     

    rolling pect = 
    VAR currIndex =
        MAX ( 'Table'[Index] )
    VAR rolling =
        CALCULATE (
            SUM ( 'Table'[Hours] ),
            FILTER ( ALLSELECTED ( 'Table' ), [Index] <= currIndex )
        )
    VAR total =
        CALCULATE ( SUM ( 'Table'[Hours] ), ALLSELECTED ( 'Table' ) )
    RETURN
        DIVIDE ( rolling, total, -1 )

     

    Full query:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYuec1MS8zLx0INPIQClWB6uMIapMcGpRGUTCGCJhBGQ6oUgYoUogmWUKN8oZzRKgTCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Team = _t, Person = _t, Reason = _t, Hours = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Team", Int64.Type}, {"Person", type text}, {"Reason", type text}, {"Hours", Int64.Type}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Person"}, {{"Count", each _, type table [Team=nullable number, Person=nullable text, Reason=nullable text, Hours=nullable number]}}),
        #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
        #"Expanded Count" = Table.ExpandTableColumn(#"Added Index", "Count", {"Team", "Reason", "Hours"}, {"Team", "Reason", "Hours"})
    in
        #"Expanded Count"

     

    Regards,

    Xiaoxin Sheng

7 Replies

    • Jarrod's avatar
      Jarrod
      Helper III

      Hi, could you please post as an attachemnt? I cannot access Google Drive.

  • Hi,

    How have you calculated the % under the Cumulative % column?  Also, show the expected result under various drill up and drill down scenarios.

  • It is just hardcoded in Excel as an example. I am trying to build a Pareto chart.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Jarrod,

      You can add an index field on query edit side based on person group, then you can write a more formula to calculate the cumulative percent based on current index.

       

      rolling pect = 
      VAR currIndex =
          MAX ( 'Table'[Index] )
      VAR rolling =
          CALCULATE (
              SUM ( 'Table'[Hours] ),
              FILTER ( ALLSELECTED ( 'Table' ), [Index] <= currIndex )
          )
      VAR total =
          CALCULATE ( SUM ( 'Table'[Hours] ), ALLSELECTED ( 'Table' ) )
      RETURN
          DIVIDE ( rolling, total, -1 )

       

      Full query:

       

      let
          Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYuec1MS8zLx0INPIQClWB6uMIapMcGpRGUTCGCJhBGQ6oUgYoUogmWUKN8oZzRKgTCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Team = _t, Person = _t, Reason = _t, Hours = _t]),
          #"Changed Type" = Table.TransformColumnTypes(Source,{{"Team", Int64.Type}, {"Person", type text}, {"Reason", type text}, {"Hours", Int64.Type}}),
          #"Grouped Rows" = Table.Group(#"Changed Type", {"Person"}, {{"Count", each _, type table [Team=nullable number, Person=nullable text, Reason=nullable text, Hours=nullable number]}}),
          #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
          #"Expanded Count" = Table.ExpandTableColumn(#"Added Index", "Count", {"Team", "Reason", "Hours"}, {"Team", "Reason", "Hours"})
      in
          #"Expanded Count"

       

      Regards,

      Xiaoxin Sheng