Forum Discussion
How to sum multiple rows from another table
Can you provide some sample data jk8979356 per the links below? For a rough overview on the direction to go, see this code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTIEYlMgtlSK1YlWSgKyjKAi5uZgoWQg0xiIzYDYAiySAmQVgRSAFcbGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Subsidiary = _t, Category = _t, #"2019 Sales" = _t, #"2020 Sales" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"2019 Sales", Int64.Type}, {"2020 Sales", Int64.Type}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Subsidiary", "Category"}, "Attribute", "Value"),
#"Extracted First Characters" = Table.TransformColumns(#"Unpivoted Other Columns", {{"Attribute", each Text.Start(_, 4), type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Extracted First Characters",{{"Attribute", "Year"}, {"Value", "Sales"}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Year", Int64.Type}})
in
#"Changed Type1"
Turns this:
into this:
Which is where MattAllington was going as far as properly modeling your data before bringing it into the Data Model. Now you can connect that to a Date Table and do all sorts of things easily.
How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.
How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum