Forum Discussion
Jarrod
2 years agoHelper III
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 % ...
- Anonymous2 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
Jarrod
2 years agoHelper III
It is just hardcoded in Excel as an example. I am trying to build a Pareto chart.
- Anonymous2 years agoNot 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