2015/11/23

Power BI - 13 - Power Query Text.Format

Power Query の追加/更新された関数について
プレースホルダ と カルチャを指定できる文字列への変換。

Text.Format
Text.Format(formatString as text, argument as any, optional culture as nullable text) as text
引数 'argument' は、list もしくは record
プレースホルダは 引数 'argument' が list のとき、#{n}、record のとき、#[fieldname]
引数 'culture' は、Text.From と同じ

Power BI - 12 - Power Query Text.Middle vs Text.Range

Power Query の追加/更新された関数について
"Text.Middle vs Text.Range" としましたが、Text.Middle でいいじゃんという内容。いずれも引数は変わらず文字列の切り出しができるが、引数 'count' 範囲外の扱いが異なる。

Text.Range (MSDN - Text.Range)
Text.Range(text as nullable text, offset as number, optional count as nullable number) as nullable text

Text.Middle
Text.Middle(text as nullable text, start as number, optional count as nullable number) as nullable text

2015/11/14

Office Insider が始まりました。

Office Insider が始まりました。日本語サイトはまだなのだけど、ja-jp 環境であってもこの先に追加される Office の新しい機能などを試すことができる。
追加されていく機能は、
What's New and Improved in Office 2016 for Office 365
で公開されるものなのだろうけど、Current Branch(CB)より先にリリースされる FirstReleaseCurrent という更新スケジュールになる。対象は C2R のサブスクリプション製品ということだろう。

2015/11/08

Power BI - 11 - Zabbix API を Power Query で使ってみる

Web.Contents (Power Query) を使うとコンテンツのダウンロードができる。バイナリコンテンツを加工することで必要なデータにすることができるのだけど、POST が必要な Webサービスもあるので。
Web.Contents(url as text, optional options as nullable record) as binary
引数 "options" を使ってリクエスト時に Content などを渡すとよい。そこで、Zabbix を使うことがあったので、Power Query + Zabbix API を試してみた。なお、Zabbix API は JSON-RPC というプロトコルなので、JSON 形式のパラメータを送信 / JSON 形式で結果を受信する。Content-Type は application/json-rpc。

例えば、Zabbix API のバージョンを得るためのリクエストは、
{
    "jsonrpc": "2.0",
    "method": "apiinfo.version",
    "params": [],
    "id": 1
}
こんな感じなので、Power Query では
let
    ZabbixServer = "http://Server/zabbix/api_jsonrpc.php",
    RequerstJSON = Text.Format(
         "{""jsonrpc"":""2.0"",""method"":""apiinfo.version"",""id"":#{0}}",
         {Number.Round(Number.RandomBetween(1,9999))}
    ),
    Options = [Headers = [#"Content-Type" = "application/json-rpc"],
               Content = Text.ToBinary(RequerstJSON)],
    Response = Web.Contents(ZabbixServer, Options),
    ImportedJSON = try Json.Document(Response),
    Result = if ImportedJSON[HasError] 
             then ImportedJSON[Error]
             else if ImportedJSON[Value][id] = null 
                  then ImportedJSON[Value][error]
                  else ImportedJSON[Value]
in
    Result