-
Notifications
You must be signed in to change notification settings - Fork 13
/
get-DataFromDifferentDataset.pq
73 lines (73 loc) · 2.99 KB
/
get-DataFromDifferentDataset.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
let
output =
(generatedToken as text, datasetId as text, tableName as text, optional daxQuery as text) =>
let
daxQueryForCall =
if daxQuery = null then
"VALUES( " & tableName & " )"
else
daxQuery,
apiCall =
Json.Document(
Web.Contents(
"https://api.powerbi.com/v1.0/myorg",
[
RelativePath = "datasets/" & datasetId & "/executeQueries",
Headers = [
#"Content-Type" = "application/json",
Authorization = generatedToken
],
Content =
Text.ToBinary(
"
{
""queries"":[
{
""query"": ""EVALUATE "
& daxQueryForCall
& """
}
],
""serializerSettings"":{
""includeNulls"": false
}
}
"
)
]
)
),
response =
let
initSource = apiCall[results]?{0}?[tables]?{0}?[rows]?,
namesOfColumns = List.Buffer(Record.FieldNames(initSource{0})),
correctedColumnsNames =
List.Transform(
namesOfColumns,
each Text.BetweenDelimiters(_, "[", "]")
),
tableCreator =
Table.FromList(
initSource,
Record.FieldValues,
correctedColumnsNames
)
in
tableCreator
in
response,
documentation = [
Documentation.Name = " get-DataFromDifferentDataset.pq ",
Documentation.Description = " Get data from different dataset stored in Power BI Service ",
Documentation.Source = "https://www.jaknapowerbi.cz",
Documentation.Version = " 1.0 ",
Documentation.Author = " Štěpán Rešl "
]
in
Value.ReplaceType(
output,
Value.ReplaceMetadata(
Value.Type(output),
documentation
)
)