我使用Kohera的Power Pivot公式在Power Query中获取Google Analytics数据:让
analytics = "https://www.googleapis.com/analytics/v3/data/ga?access_token=",
addAccessToken = analytics &
Excel.CurrentWorkbook(){[Name="TblToken"]}[Content]{0}[Access Token],
addViewId = addAccessToken & "&ids=ga:33784873",
addStartDate = addViewId & "&start-date=2014-10-01",
addEndDate = addStartDate & "&end-date=2014-12-31",
addDimensions = addEndDate & "&dimensions=ga:operatingSystem",
url = addDimensions & "&metrics=ga:sessions",
GaJson = Json.Document(Web.Contents(url)),
GetRows = GaJson[rows],
TableFromList = Table.FromList(GetRows, Splitter.SplitByNothing(),
null, null, ExtraValues.Error),
ColOS = Table.AddColumn(TableFromList, "OS", each [Column1]{0}),
ColCount = Table.AddColumn(ColOS, "Count", each [Column1]{1}),
RemoveFirstColumn = Table.RemoveColumns(ColCount,{"Column1"}) in RemoveFirstColumn
但是,如何添加更多列?例如,如果我想查询ga:hostname、ga:country、ga:browser,我该如何在M代码中获得它?非常感谢。
好吧,我已经想通了。为他人解释:
TableFromList = Table.FromList(GetRows, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
ColHostname = Table.AddColumn(TableFromList, "Hostname", each [Column1]{0}),
ColCountry = Table.AddColumn(ColHostname, "Country", each [Column1]{1}),
ColBrowser = Table.AddColumn(ColCountry, "Browser", each [Column1]{2}),
ColCount = Table.AddColumn(ColBrowser, "Count", each [Column1]{3}),
RemoveFirstColumn = Table.RemoveColumns(ColCount,{"Column1"})