Search code examples
excelpowerbidaxpowerquerym

Formatting a list into a table in PowerBI/Excel


I have a list in my Excel file as folowing :

enter image description here

As you can see i only have the values in one column the others are blanks, i want the folowing result as a table :

enter image description here

i have more than 99 row, can someone help with dax or M code Thank you !


Solution

  • If it is always three rows, blank, three rows, you can do this in powerquery, pasted into home...advanced editor...

    let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    row_groupings = 3,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Name] <> null and [Name] <> "")), 
    #"Added Index" = Table.AddIndexColumn(#"Filtered Rows", "Index", 0, 1, Int64.Type),
    #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 0, 1, Int64.Type),
    Column = Table.TransformColumns(#"Added Index1",{{"Index", each Number.Mod(_, row_groupings), Int64.Type}}),
    Row = Table.TransformColumns(Column,{{"Index.1",each Number.IntegerDivide(_, row_groupings), Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(Row, {{"Index", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(Row, {{"Index", type text}}, "en-US")[Index]), "Index", "Name"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index.1"})
    in  #"Removed Columns"
    

    enter image description here