Brijesh Maurya
Brijesh Maurya

Reputation: 125

Trying to create & then expand a table with m code in power query

I am using power query m language. I have created a blank query & written this code

let
    Source =  #table(                
                {"first", "second"},
                {
                    {Table.ExpandRecordColumn(Table.FromRecords({[order_id = "a_01", place = "america", price = 700]}), "first", {"order_id", "place", "price"}), "dd"}
                }
              )
in
    Source

Actually I am trying to create a table with code & immediately trying to expand it within first column. But it's showing following error Expression.Error: The column 'first' of the table wasn't found. Details: first

I cannot figure out the problem. Please help me.

Upvotes: 0

Views: 337

Answers (2)

Marc Pincince
Marc Pincince

Reputation: 5192

Is this what you're trying to do?

let
Source =  #table(                
            {"first", "second"},
            {
               {Table.ExpandRecordColumn(Table.FromRecords({[first = [order_id = "a_01", place = "america", price = 700]]}), "first", {"order_id", "place", "price"}), "dd"}
            }
          ),
#"Expanded first" = Table.ExpandTableColumn(Source, "first", {"order_id", "place", "price"}, {"order_id", "place", "price"})
in
#"Expanded first"

It gives this output:

enter image description here

Upvotes: 1

first is not a column the table you passed into Table.ExpandRecordColumn. Those columns are order_id, place, and price. If you want to expand the first column in the table you made with #table, you need to use Table.ExpandTableColumn and it needs to use the table made with #table as its first parameter.

Upvotes: 0

Related Questions