简体   繁体   English

Excel Power Query - 来自具有动态工作表单元格值的网络

[英]Excel Power Query - from web with dynamic worksheet cell value

We have a spreadsheet that gets updated monthly, which queries some data from our server.我们有一个每月更新的电子表格,它从我们的服务器查询一些数据。

The query url looks like this:查询 url 如下所示:

http://example.com/?2016-01-31

The returned data is in a json format, like below:返回的数据为json格式,如下图:

{"CID":"1160","date":"2016-01-31","rate":{"USD":1.22}}

We only need the value of 1.22 from the above and I can get that inserted into the worksheet with no problem.我们只需要上面的 1.22 值,我可以毫无问题地将其插入到工作表中。

My questions: 1. How to use a cell value [contain the date] to pass the date parameter [2016-01-31] in the query and displays the result in the cell next to it.我的问题: 1.如何使用单元格值[包含日期]在查询中传递日期参数[2016-01-31]并在其旁边的单元格中显示结果。 2. There's a long list of dates in a column, can this query be filled down automatically per each date? 2. 一列有很长的日期列表,这个查询可以按每个日期自动填写吗? 3. When I load the query result to the worksheet, it always load in pairs. 3.当我将查询结果加载到工作表时,它总是成对加载。 [taking up two cells, one says "Value", the other contains the value which is "1.22" in my case]. [占用两个单元格,一个表示“值”,另一个包含在我的情况下为“1.22”的值]。 Ideally I would only need "1.22", not the title, can this be removed?理想情况下,我只需要“1.22”,而不是标题,可以删除吗? [Del won't work, will give you a "Column 1" instead, or you have to hide the entire row which will mess up with the layout]. [Del 不起作用,会给你一个“第 1 列”,或者你必须隐藏整行,这会扰乱布局]。

I know this is a lot to ask but I've tried a lot of search and reading in the last few days and I have to say the M language beats me.我知道有很多问题要问,但在过去几天里我尝试了很多搜索和阅读,我不得不说 M 语言打败了我。

Thanks in advance.提前致谢。

  1. Convert your Web.Contents() request into a function:将您的 Web.Contents() 请求转换为函数:

     let myFunct = ( param as date ) => let x = Web.Contents(.... & Date.ToText(date) & ....) in x in myFunct
  2. Reference your data request function from a new query, include any transformations you need (in this case JSON.Document, table expansions, remove extraneous data. Feel free to delete all the extra data here, including columns that just contain the label 'value'.从新查询中引用您的数据请求函数,包括您需要的任何转换(在本例中为 JSON.Document、表扩展、删除无关数据。请随意删除此处的所有额外数据,包括仅包含标签“值”的列.

  3. (assuming your table of domain values already exists) add a custom column like (假设您的域值表已经存在)添加一个自定义列,如

    =Expand(myFunct( [someparameter] ))

edit: got home and got into my bookmarks.编辑:回到家并进入我的书签。 Here is a more detailed reference for what you are looking to do: http://datachix.com/2014/05/22/power-query-functions-some-scenarios/这是您要执行的操作的更详细参考: http : //datachix.com/2014/05/22/power-query-functions-some-scenarios/

For a table - Add column where you get data and parse JSON对于表 - 添加获取数据和解析 JSON 的列

let
    tt=#table(
        {"date"},{
        {"2017-01-01"},
        {"2017-01-02"},
        {"2017-01-03"}
    }),
    add_col = Table.AddColumn(tt, "USD", each Json.Document(Web.Contents("http://example.com/?date="&[date]))[rate][USD])
in
    add_col

If you need only one value如果您只需要一个值

Json.Document(Web.Contents("http://example.com/?date="&YOUR_DATE_STRING))[rate][USD]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM