Forum Discussion

WM117's avatar
WM117
Frequent Visitor
2 years ago
Solved

Generate new rows based on Quarter Year table in Power Query

Hi Everybody,   I want to generate extra rows in my dataset based on the column QuarterYear   Current situation QuarterYear Q1-2023 Q2-2023 Q3-2023 Q4-2023 Q1-2024 Q2-2024 ...
  • tackytechtom's avatar
    2 years ago

    Hi WM117 ,

     

    How about this:

     

    I first created a lookup table called TableQM specifying the months per quarter:

     

    Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcqxDQAgCEXBXaw1UfgMYk3Yfw2J1euuuMxxz7JtPmq2DXZY8P/CF77whR/4gR/47Xo=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [QuarterYear = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Custom", each [QuarterYear]),
        #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom", "Custom", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"Custom.1", "Custom.2"}),
        #"Merged Queries" = Table.NestedJoin(#"Split Column by Delimiter", {"Custom.1"}, TableQM, {"Quarter"}, "TableQM", JoinKind.LeftOuter),
        #"Expanded TableQM" = Table.ExpandTableColumn(#"Merged Queries", "TableQM", {"Month"}, {"TableQM.Month"}),
        #"Added Custom1" = Table.AddColumn(#"Expanded TableQM", "Custom", each [TableQM.Month] & "/" & Text.End([Custom.2], 2)),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom.1", "Custom.2", "TableQM.Month"})
    in
        #"Removed Columns"

     

    Let me know if this solves the issue 🙂

     

    /Tom
    https://www.tackytech.blog/
    https://www.instagram.com/tackytechtom/