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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

Guys, I am new to M language and testing some queries in the power query editor. My query is very simple:

 

(Startdate as datetime, Enddate as datetime) =>
let

start=Number.From(Date.From(Startdate)),
end=Number.From(Date.From(Enddate))-1,

filterdates= List.Distinct( List.Transform( {start..end}, each Text.From( DateTime.Date(Date.From(_))))),
Source=Json.Document(Web.Contents("https://instance.service-now.com/api/now/table/task")),
#"Filtered Rows"=Table.SelectRows(Source,filterdates),
#"Converted to Table" = Table.FromList(#"Filtered Rows", Splitter.SplitByNothing())
in
#"Converted to Table"

 

I am receiving this error 

An error occurred in the ‘’ query. Expression.Error: We cannot convert a value of type Record to type Table.
Details:
Value=[Record]
Type=[Type]

tried solving this with a solution available but no success. Please help

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi @Anonymous , 

It seems that you want to get date range based on parameter, if so, you could try below M code

(Startdate as date, Enddate as date) =>
let

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtA31DdU0lEyNFKK1YGLGIFETJFFjIEiRgbIIqYgNSgiZkARY2QBQ7A5CBEjsFVmSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [date = _t, amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type date}, {"amount", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [date] >= Startdate and [date] < Enddate)
in
    #"Filtered Rows"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
dax
Community Support
Community Support

Hi @Anonymous , 

It seems that you want to get date range based on parameter, if so, you could try below M code

(Startdate as date, Enddate as date) =>
let

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtA31DdU0lEyNFKK1YGLGIFETJFFjIEiRgbIIqYgNSgiZkARY2QBQ7A5CBEjsFVmSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [date = _t, amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type date}, {"amount", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [date] >= Startdate and [date] < Enddate)
in
    #"Filtered Rows"

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Smauro
Solution Sage
Solution Sage

Hi @Anonymous 

Json.Document returns record types, so when using Table.SelectRows it throws an error.
You could add an intermediary step to transform your record to table before selecting rows (Record.ToTable) and it should work.




Feel free to connect with me:
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors