Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
kitala11
Helper III
Helper III

Column does not exist sometimes

Hello,
I am facing a unique issue. 
Basically there is this error "Column in table cannot be found or may not be used in this expression".

Because in my query editor, I am pivoting a column as I want to break it down into diff types for example

1   Apple 5

2   Orange 7

3   Grapes 3
4   Grapes 3
5   Apple 1

 

to 

    Apple Orange Grapes

1    5          null   null

2    null       7       null

3 null        null     3

4... etc.

5
 

However, sometimes there may not be any apples sold for instance. Then this pivoted column wouldn't exist. Then my calculation would have a problem because i sum the apples orange and grapes. But if apples as a column dont exist. I get that error.
Anyone knows how to circumvent this?

4 REPLIES 4
Vera_33
Resident Rockstar
Resident Rockstar

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

 

Vera_33_0-1615438960398.png

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

@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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
amitchandak
Super User
Super User

@kitala11 , In such a case it possible to use a matrix visual, fruit on the column.

 

There is another way, creating measures for each of them. See if calculation groups can help https://www.sqlbi.com/blog/marco/2020/07/15/creating-calculation-groups-in-power-bi-desktop/

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.