Forum Discussion
How to append multiple columns from inside one table
- 6 years ago
Hi apoje
I am not sure why you've completely ignored my solution all along 🤔. It does exactly what you showed in your first post in a simple way. If the base table is "tbl_bundle" in the files you've shared, you can create a blank query with the following M code and you'll get the result. It is the same as I posted a couple of days ago already:
let Source = tbl_bundle, #"Removed Columns" = Table.RemoveColumns(Source,{"SKU-bundleID"}), ExtractColumns_ = Table.ToColumns(#"Removed Columns"), ContentCols_ = List.Combine(List.Alternate(ExtractColumns_,1,1,1)), QuantityCols_ = List.Combine(List.Alternate(ExtractColumns_,1,1,0)), final_ = Table.FromColumns({ContentCols_, QuantityCols_}, {"ContentAll", "QuantityAll"}) in final_Please mark the question solved when done and consider giving kudos if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
hi ibarrau you are right my phrasing was off. The result would actually be a new table.
= Table.Combine({
Table.RenameColumns(
Table.SelectColumns(tblSL, "var-nr-1", "Multiplication.1")
,{{"var-nr-1", "var-nr"},{"Multiplication.1", "Quantity"} })
,
Table.RenameColumns(
Table.SelectColumns(tblSL, "var-nr-2", "Multiplication.2")
,{{"var-nr-2", "var-nr"},{"Multiplication.2", "Quantity"} })
,
Table.RenameColumns(
Table.SelectColumns(tblSL, "var-nr-3", "Multiplication.3")
,{{"var-nr-3", "var-nr"},{"Multiplication.3", "Quantity"} })
,
Table.RenameColumns(
Table.SelectColumns(tblSL, "var-nr-4", "Multiplication.4")
,{{"var-nr-4", "var-nr"},{"Multiplication.4", "Quantity"} })
})
I have created a blank query and written the code as you suggested. However I am getting an error message
Expression.Error: We cannot convert the value "Multiplication.1" to type Number.
Details:
Value=Multiplication.1
Type=[Type]
All the Multiplication columns are a whole number type. I am not sure how to amend the error...
Regards,
Andraz
Ok good. The error doesn't look that is coming from that code. It says it's trying to convert multiplication.1 to number and it can't do it. Check your previous o next steps and check if you have a convert to number somewhere. You might have wrong data in the column that is not allowing you to convert it or apply math over the column.
You can always check my code by parts. Starting without the combine to see if it works:
Table.RenameColumns(
Table.SelectColumns(tblSL, "var-nr-1", "Multiplication.1")
,{{"var-nr-1", "var-nr"},{"Multiplication.1", "Quantity"} })
If you want you can share previous steps so we can help you find the error.
Regards,