This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hi all,
I have a data sheet with sales and visits in a single worksheet.
I was trying to transform into a single table but could get it right.
Can someone help me with it. Thank you so much.
Solved! Go to Solution.
Hi @mofu1401
Please see this sample query
let
Source = Excel.Workbook(File.Contents("filepath"), null, true),
FY23_Sheet = Source{[Item="FY23",Kind="Sheet"]}[Data],
#"Filtered Rows" = Table.SelectRows(FY23_Sheet, each [Column1] <> null and [Column1] <> ""),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Category", each if [Column1] = "Sales" or [Column1] = "Visit" then [Column1] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Category"}),
#"Grouped Rows" = let
Source = #"Filled Down", // Your source table
ColumnsList = Table.ColumnNames(Source),
TypesList = List.Transform(ColumnsList, each if _ = "Category" then "text" else "any"),
TypeExpression = "type table [" & Text.Combine(List.Transform(List.Zip({ColumnsList, TypesList}), each _{0} & "=" & _{1}), ", ") & "]",
TypeRecord = Expression.Evaluate(TypeExpression, #shared),
Grouped = Table.Group(Source, {"Category"}, {{"Grouped", each _, TypeRecord}})
in
Grouped,
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Grouped Transformed", each let
PromotedHeaders =
Table.PromoteHeaders([Grouped], [PromoteAllScalars = true]),
AutomaticallyRenamedColumns = Table.RenameColumns(PromotedHeaders, {{Table.ColumnNames(PromotedHeaders){0}, "Customer"}} ),
Unpivoted = Table.UnpivotOtherColumns ( AutomaticallyRenamedColumns, {"Customer"}, "Date", "Value")
in Unpivoted),
#"Expanded Grouped Transformed" = Table.ExpandTableColumn(#"Added Custom1", "Grouped Transformed", {"Customer", "Date", "Value"}, {"Customer", "Date", "Value"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Grouped Transformed",{{"Date", type date}}),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Changed Type", {"Date"}),
#"Removed Columns" = Table.RemoveColumns(#"Removed Errors",{"Grouped"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Category]), "Category", "Value", List.Sum),
#"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"Customer", type text}, {"Sales", type number}, {"Visit", Int64.Type}})
in
#"Changed Type1"
Here it is. Just change the path to the file.
Hi @mofu1401
Please see this sample query
let
Source = Excel.Workbook(File.Contents("filepath"), null, true),
FY23_Sheet = Source{[Item="FY23",Kind="Sheet"]}[Data],
#"Filtered Rows" = Table.SelectRows(FY23_Sheet, each [Column1] <> null and [Column1] <> ""),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Category", each if [Column1] = "Sales" or [Column1] = "Visit" then [Column1] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Category"}),
#"Grouped Rows" = let
Source = #"Filled Down", // Your source table
ColumnsList = Table.ColumnNames(Source),
TypesList = List.Transform(ColumnsList, each if _ = "Category" then "text" else "any"),
TypeExpression = "type table [" & Text.Combine(List.Transform(List.Zip({ColumnsList, TypesList}), each _{0} & "=" & _{1}), ", ") & "]",
TypeRecord = Expression.Evaluate(TypeExpression, #shared),
Grouped = Table.Group(Source, {"Category"}, {{"Grouped", each _, TypeRecord}})
in
Grouped,
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Grouped Transformed", each let
PromotedHeaders =
Table.PromoteHeaders([Grouped], [PromoteAllScalars = true]),
AutomaticallyRenamedColumns = Table.RenameColumns(PromotedHeaders, {{Table.ColumnNames(PromotedHeaders){0}, "Customer"}} ),
Unpivoted = Table.UnpivotOtherColumns ( AutomaticallyRenamedColumns, {"Customer"}, "Date", "Value")
in Unpivoted),
#"Expanded Grouped Transformed" = Table.ExpandTableColumn(#"Added Custom1", "Grouped Transformed", {"Customer", "Date", "Value"}, {"Customer", "Date", "Value"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded Grouped Transformed",{{"Date", type date}}),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Changed Type", {"Date"}),
#"Removed Columns" = Table.RemoveColumns(#"Removed Errors",{"Grouped"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Category]), "Category", "Value", List.Sum),
#"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"Customer", type text}, {"Sales", type number}, {"Visit", Int64.Type}})
in
#"Changed Type1"
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 36 | |
| 33 | |
| 31 | |
| 24 | |
| 18 |
| User | Count |
|---|---|
| 68 | |
| 50 | |
| 33 | |
| 24 | |
| 24 |