Forum Discussion
Column does not exist sometimes
Hi kitala11
You are pivoting in Power Query Editor? Select the first two column, pivot the last column. Paste in Advanced Editor to see it
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjy0QElH6dACx4KCnFQgy1QpVidayQgq6l+UmJcOEjYHCxtDhd2LEgtSi4FMY7CwCXZhUzSjDZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", type text}, {"Column3", Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Column2]), "Column2", "Column3", List.Sum)
in
#"Pivoted Column"
Hi, I don't think taht answers my question. Let me emphasise the key point so its more understandable.
sometimes there may not be any apples sold for instance. Then this pivoted column wouldn't exist. There will not be a column called Apple to begin with if it doesn't exist as a record because no apple was sold.
This is the problem I am trying to solve. My measures involves calculating the sum of apple grapes and orange. but if apples dont exist, the apple column wouldn't exist and my calculated measure would have an error
- amitchandak5 years agoSuper User
kitala11 , One solution I was saying is not to unpivot. Just create measure like
Apple = Sumx(filter(Table, Table[fruit] ="Apple"), [Value])
Orange= Sumx(filter(Table, Table[fruit] ="Orange"), [Value])
but this means to much of measures, that is why I suggested to explore calculation groups, if they can help to reduce it