Forum

Expression.Error: W...
 
Notifications
Clear all

Expression.Error: We cannot convert a value of type Record to type Number.

6 Posts
2 Users
0 Reactions
826 Views
(@gsasser)
Posts: 6
Active Member
Topic starter
 

Hi All,

I am getting this error message:

Expression.Error: We cannot convert a value of type Record to type Number. Details: Value=[Record] Type=[Type]

with the following Power Query code

let
Source = Excel.CurrentWorkbook(){[Name="ARV_Table"]}[Content],

// Step 1: Filter data
FilteredRows = Table.SelectRows(Source, each [Address] <> null and [DCK ARV] = null),

// Step 2: Construct API URLs
ConstructedURLs = Table.AddColumn(FilteredRows, "API_URL", each "https://api.rentcast.io/v1/avm/value?address=" & Uri.EscapeDataString([Address]) & "%2C%20" & Uri.EscapeDataString([City]) & "%2C%20TX%2C%20" & Text.From([ZipCode])),

// Step 3: Invoke the API and parse the JSON response
InvokeAPI = Table.AddColumn(ConstructedURLs, "API_Response", each Record.Field(Json.Document(Web.Contents([API_URL]{0}), "price"), [Headers=[#"X-API-Key"="api-key"]])),

// Step 4: Extract the Price value from the JSON response
ExtractPrice = Table.AddColumn(InvokeAPI, "Price", each [API_Response][price]),

// Step 5: Remove unnecessary columns
Result = Table.SelectColumns(ExtractPrice, {"Address", "DCK ARV", "Price"})
in
Result

 

The data table is Address, City, ZipCode, DCK ARV

I have provided code only in place of the workbook because it contains API keys. I retracted the sensitive data. Please help if you can, I appreciate any guidance.

Regards,

Greg Sasser

 
Posted : 29/07/2023 6:03 pm
Philip Treacy
(@philipt)
Posts: 1632
Member Admin
 

Hi Greg,

It's hard to help because I don't have the file and code that you are using.  Can you make a copy of the file, change the API credentials then save it and upload here?

I'll create an account with RentCast, get my own API key and try that with your code.  

regards

Phil

 
Posted : 29/07/2023 9:11 pm
(@gsasser)
Posts: 6
Active Member
Topic starter
 

Hi Philip,

I appreciate your help! I made a copy of the file with the data and code. I retracted the API Key in the code, and if you need it, I can send it to you directly. 

Please take a look at the file I've attached. 

Thank you so much!

Greg

 
Posted : 29/07/2023 10:32 pm
Philip Treacy
(@philipt)
Posts: 1632
Member Admin
 

Hi Greg,

The syntax of Record.Field around the API call wasn't right.  The "price" field name was in the wrong place.

This works

= Record.Field(Json.Document(Web.Contents([API_URL], [Headers=[#"X-API-Key"="xxx"]])), "price")

See attached file

regards

Phil

 
Posted : 31/07/2023 8:35 pm
(@gsasser)
Posts: 6
Active Member
Topic starter
 

Hi Phil,

I want to express my sincere gratitude for your kindness. Your help means a lot to me.

Best regards,

Greg

 
Posted : 01/08/2023 4:09 pm
Philip Treacy
(@philipt)
Posts: 1632
Member Admin
 

You're welcome Greg, glad to be able to help.

regards

Phil

 
Posted : 01/08/2023 6:31 pm
Share: