Forum Discussion

gigotomo's avatar
gigotomo
Frequent Visitor
3 years ago
Solved

Transform into multiple rows from particular cell value

I have the below table.   Market Date Value Spain 8/26/2022 25 UK 8/26/2022 23 Italy 8/26/2022 29 All 8/26/2022 19   Whenever the Market is "All" i wish to create mult...
  • gigotomo's avatar
    3 years ago

    I found a simpler solution using "Split Column" (into Rows).

     

    I created a conditional column saying if market is "All" then "abc" else the "market"

    Then i used split column (into rows) so I get 3 rows wth the market "All"

     

    then i created the final "Market1" column based on the values

     

    let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Market", type text}, {"Date", type text}, {"Value", Int64.Type}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "DummY_market", each if [Market] = "All" then "abc" else null),
    #"Split Column by Position" = Table.ExpandListColumn(Table.TransformColumns(#"Added Conditional Column", {{"DummY_market", Splitter.SplitTextByRepeatedLengths(1), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "DummY_market"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Position",{{"DummY_market", type text}}),
    #"Added Conditional Column1" = Table.AddColumn(#"Changed Type1", "Market1", each if [DummY_market] = null then [Market] else if [DummY_market] = "a" then "Spain" else if [DummY_market] = "b" then "UK" else if [DummY_market] = "c" then "IT" else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column1",{"DummY_market"})
    in
    #"Removed Columns"