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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. 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

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
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/

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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