Forum Discussion

Jamie9979's avatar
Jamie9979
New Member
4 years ago
Solved

Very beginner level question: Graph budget when multiple years of budget is in a single row

Hi,  Apologies for this very simple question, I just can't get my head around it.   I have data which in the most basic form is this: ArticleName     Budget in N-1        Budget in N        Budge...
  • PC2790's avatar
    4 years ago

    Hey Jamie9979 ,

     

    As per my interpretation of your requirement, you are looking for something like this:

    If yes, this is how I achieved it:

    1) In Power Query, I unpivoted the columns having budget

    2) I split the column names to derive the year

    3) Renamed the columns with meaningful names and removed unwanted column.

    The M code looks like:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi1IL0pMycxLVwhwjik1MDAyL1bSUTI0BRJGBiACxDJQitWJVnIqrQSpy81MTgWKQcRhNEjeL7VcISexoCS/AGSEMUjSBKwCRJgB1cQCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Article = _t, #"Budget 2021" = _t, #"Budget 2022" = _t, #"Budget 2023" = _t, #"Budget 2024" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Article", type text}, {"Budget 2021", Int64.Type}, {"Budget 2022", Int64.Type}, {"Budget 2023", Int64.Type}, {"Budget 2024", Int64.Type}}),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Article"}, "Attribute", "Value"),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Attribute.2", "Year"}, {"Value", "BudgetValue"}}),
        #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Attribute.1"})
    in
        #"Removed Columns"

    Also, attaching the pbix file here for your reference.