我试图在转换为表格后扩展列,但是这些列需要动态扩展。
我在线上进行了研究,但是我添加的代码无法以某种方式起作用。我一定想念什么,但我不确定。
这是我的代码:
let
Date = DateTime.ToText((DateTime.LocalNow()), "yyyy-MM-dd"),
Date2 = Date.ToText((Date.AddDays(Date.From(DateTime.FixedLocalNow()),-90)), "yyyy-MM-dd"),
Source = Json.Document(Web.Contents("https://www.findmyshift.com/staff-view?r=2rr67u5y9i&apikey=***********&format=json&start=" & Date2 & "&finish=" & Date)),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", List.Accumulate(#"Converted to Table"[Column1], {}, (state, current) => List.Union({state, Table.ColumnNames(current)}))),
#"Replaced Value" = Table.ReplaceValue(#"Expanded Column1","'","'",Replacer.ReplaceText,{"Column1.Name"}),
#"Renamed Columns" = Table.TransformColumnNames(#"Replaced Value", (columnName as text) as text => Text.Replace(columnName, "Column1.", ""))
任何帮助将不胜感激。
答案 0 :(得分:0)
尝试通过以下代码替换步骤#“ Expanded Column1” :
= Table.ExpandRecordColumn(#"Converted to Table", "Column1",
Record.FieldNames(#"Converted to Table"{0}[Column1]))
答案 1 :(得分:0)
我认为您应该从问题中删除API密钥,您可能不希望其他人使用您的凭据滥用/访问此服务。 (最好请服务提供商向您提供一个新的API密钥作为替换,这样没人可以在您的答案中使用该密钥。)
如果用实际的API密钥(在双引号之间)替换"REPLACE ME WITH YOUR API KEY"
(在下面的代码中),那么此代码应该可以完成您想做的事情。
let
startDate = Date.ToText((Date.AddDays(Date.From(DateTime.FixedLocalNow()),-90)), "yyyy-MM-dd"),
endDate = DateTime.ToText((DateTime.LocalNow()), "yyyy-MM-dd"),
jsonResponse =
let
response = Web.Contents("https://www.findmyshift.com/staff-view", [Query = [r = "2rr67u5y9i", apikey = "REPLACE ME WITH YOUR API KEY", format = "json", start = startDate, finish = endDate]]),
json = Json.Document(response)
in
json,
toTable = Table.FromRecords(jsonResponse),
replaceValue = Table.ReplaceValue(toTable, "'", "'", Replacer.ReplaceText, Table.ColumnNames(toTable)) // Replace in all columns
in
replaceValue
Table.FromRecords
可以完成您想做的事情(无需扩展和重命名所有动态列)Web.Contents
可以为您构建查询字符串(并将自动处理URL编码),前提是您将参数传递给Query
参数。