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.
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
Solved! Go to Solution.
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.
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.
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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.