Reputation: 683
I'm pretty new at Power BI (so forgive my rough terminology), and I'm trying to create a bar chart from some existing financial data. Specifically, I'd like to know how to transform my data. I've looked at DAX and python, and can't quite figure out the right commands.
My existing table looks like the following. The set of categories are arbitrary (not known up front, so can't be hardcoded), same with the set of years.
Category 2002 2003 2004 2005
A $10 $75 $75 $75
B $75 $59 $75 $79
C $15 $32 $13 $5
B $23 $12 $75 $7
C $17 $88 $75 $15
And I want my output table to have the number of rows as the number of unique categories, totaling up the dollar amounts for each year.
Category 2002 2003 2004 2005
A $10 $75 $75 $75
B $98 $71 $150 $86
C $32 $120 $88 $20
What's the best way to roll up the data this way? I intend to use the resulting table to make a composite bar chart, one bar per year.
Thank you!
Upvotes: 0
Views: 283
Reputation: 12325
Aggregated =
SUMMARIZE(
'Table',
'Table'[Category],
'Table'[Year],
"Sum", SUM('Table'[Value])
)
but that's not needed for your purpose.
Upvotes: 3
Reputation: 2615
Here is the full M-Code to achieve your goal: Just change the source step with your source file:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0ABLmpkhErE60khOMb2oJl7EEyziD9ID4xkYgljFIDVyLEYhraATXgtBhDiQsLGASQANiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, #"2002" = _t, #"2003" = _t, #"2004" = _t, #"2005" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"2002", Int64.Type}, {"2003", Int64.Type}, {"2004", Int64.Type}, {"2005", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Category"}, "Attribute", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Year"}}),
#"Grouped Rows" = Table.Group(#"Renamed Columns", {"Category", "Year"}, {{"Total", each List.Sum([Value]), type number}}),
#"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[Year]), "Year", "Total", List.Sum)
in
#"Pivoted Column"
Upvotes: 1