Forum Discussion
Pivot Columns turn Error
- 7 years ago
Use unpivot columns, then all of the other Row No2 or No3 or No4 , will be all in Row No , and pallets also , All Pallets 2 or Pallets 3 or Pallets 4 only in Pallets Column.
But this will get many rows:
This is my code
let Source = Excel.Workbook(File.Contents("C:\Users\maggiel\Desktop\case\12\12.25\12.25.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"a", type text}, {"value", type any}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1), #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[a]), "a", "value"), #"Filled Up" = Table.FillUp(#"Pivoted Column",{"pallets4", "row no4", "row no2", "pallets2", "row no3", "pallets3", "pallets", "row no", "expiring date"}), #"Filled Down" = Table.FillDown(#"Filled Up",{"productname"}), #"Filtered Rows" = Table.SelectRows(#"Filled Down", each [manufcturing date] <> null and [manufcturing date] <> ""), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"Index", "productname", "manufcturing date", "expiring date", "pallets", "pallets2", "pallets3", "pallets4"}, "Attribute", "Value"), #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Value", "row no"}}), #"Unpivoted Columns1" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Index", "productname", "manufcturing date", "expiring date", "Attribute", "row no"}, "Attribute.1", "Value"), #"Renamed Columns1" = Table.RenameColumns(#"Unpivoted Columns1",{{"Value", "pallets"}}), #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns1",{"Attribute", "Attribute.1"}) in #"Removed Columns"Best Regards
Maggie
- 7 years ago
If you want the "row no1" assciated with "pallets1", instead of "pallets2","pallets3",,ect.
Please refer to my pbix below
let Source = Excel.Workbook(File.Contents("C:\Users\maggiel\Desktop\case\12\12.25\12.25.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"a", type text}, {"value", type any}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1), #"Pivoted Column" = Table.Pivot(#"Added Index", List.Distinct(#"Added Index"[a]), "a", "value"), #"Filled Up" = Table.FillUp(#"Pivoted Column",{"pallets4", "row no4", "row no2", "pallets2", "row no3", "pallets3", "pallets", "row no", "expiring date"}), #"Filled Down" = Table.FillDown(#"Filled Up",{"productname"}), #"Filtered Rows" = Table.SelectRows(#"Filled Down", each [manufcturing date] <> null and [manufcturing date] <> ""), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"Index", "productname", "manufcturing date", "expiring date", "pallets", "pallets2", "pallets3", "pallets4"}, "Attribute", "Value"), #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Value", "row no"}}), #"Unpivoted Columns1" = Table.UnpivotOtherColumns(#"Renamed Columns", {"Index", "productname", "manufcturing date", "expiring date", "Attribute", "row no"}, "Attribute.1", "Value"), #"Renamed Columns1" = Table.RenameColumns(#"Unpivoted Columns1",{{"Value", "pallets"}}), #"Inserted Last Characters" = Table.AddColumn(#"Renamed Columns1", "Last Characters_rowno", each Text.End([Attribute], 1), type text), #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Last Characters",{{"Last Characters_rowno", Int64.Type}}), #"Replaced Errors" = Table.ReplaceErrorValues(#"Changed Type1", {{"Last Characters_rowno", 1}}), #"Inserted Last Characters1" = Table.AddColumn(#"Replaced Errors", "Last Characters_pallets", each Text.End([Attribute.1], 1), type text), #"Changed Type2" = Table.TransformColumnTypes(#"Inserted Last Characters1",{{"Last Characters_pallets", Int64.Type}}), #"Replaced Errors1" = Table.ReplaceErrorValues(#"Changed Type2", {{"Last Characters_pallets", 1}}), #"Added Conditional Column" = Table.AddColumn(#"Replaced Errors1", "compare", each if [Last Characters_rowno] = [Last Characters_pallets] then 1 else 0), #"Filtered Rows1" = Table.SelectRows(#"Added Conditional Column", each [compare] = 1) in #"Filtered Rows1"Explaination for "insert last characters">
Since your columns name look like this:
“Row No. :”,” Row No. : 2”..
I extract the last character of the column “Attribute”(get this by using Unpivot columns for several row no columns), then transform the type from “text” to “whole number”, then except the “Row No. :”, others will show numbers, next replace error with 1.
The same for pallets columns.
finally, create a condition column, then filter this column.
Best Regards
Maggie
v-juanli-msfthi , i can't view each steps on edit query , it shown like this , the source can't be detected.
can you send me the file which i can see the each step how to get it done ?
i'd like to see each of both files , thanks you for your support . hope to get your prompt response very soon.
How about clicking on other steps rather than the "source"?
My last two post provides the code in Advanced editor.
This the table i create in excel, you could paste it in your excel to create a new excel like mine, then replace the file path in my two codes with the file path in your PC.
Source = Excel.Workbook(File.Contents("C:\Users\maggiel\Desktop\case\12\12.25\12.25.xlsx"), null, true),
Replace the red part with your file path
| a | value |
| productname | 2736 dasani 500ml 4*6 pet kh |
| manufcturing date | 10/22/2018 |
| expiring date | 10/22/2019 |
| row no | ភាសាខ្មែរ |
| pallets | 36 |
| row no2 | 21 |
| pallets2 | 46 |
| row no3 | 23 |
| pallets3 | 16 |
| row no4 | 12 |
| pallets4 | 18 |
| manufcturing date | 10/23/2018 |
| expiring date | 10/23/2019 |
| row no | ភាសា |
| pallets | 35 |
| row no2 | 36 |
| pallets2 | 37 |
| row no3 | 38 |
| pallets3 | 39 |
| row no4 | 40 |
| pallets4 | 41 |
| productname | pet kh |
| manufcturing date | 10/28/2018 |
| expiring date | 10/29/2019 |
| row no | ភាសាខ្មែរ |
| pallets | 11 |
| row no2 | 12 |
| pallets2 | 13 |
| row no3 | 14 |
| pallets3 | 15 |
| row no4 | 16 |
| pallets4 | 17 |
Best Regrads
Maggie
- Chanleakna1237 years agoPost Prodigy
v-juanli-msft , hi ,
thanks you so much for your support so far . the issue solved. i wanna click accept solution but it said it contains URL , blah blah ,
thanks you , once the BI Support team send me accept the solution i'll click accept.
thaks you again :)