-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathget-CumulatedValueByCategoryAndPreviousDates.pq
62 lines (62 loc) · 2.42 KB
/
get-CumulatedValueByCategoryAndPreviousDates.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
let
output =
(tbl as table, columnToCumulationName as text, categoryColumnName as text, dateColumnName as text, tableCategoryColumn as text, tableDateColumn as date) as number =>
let
getTable =
Table.Buffer(
Table.RenameColumns(
tbl,
{
{
columnToCumulationName,
"cumul"
},
{
categoryColumnName,
"category"
},
{
dateColumnName,
"dateKey"
}
}
)
),
calculator =
List.Sum(
List.Transform(
List.Select(
Table.ToRecords(getTable),
each
_[category]
= tableCategoryColumn
and _[dateKey]
<= tableDateColumn
),
each _[cumul]
)
)
in
calculator,
documentation = [
Documentation.Name = " get-CumulatedValueByCategoryAndPreviousDates.pq ",
Documentation.Description = " Return cumulated summary by specific category and previous dates. This function required Table, String names of columns: {Cumulation, Category, Date}, and Columns thats will be used as Category and DateKey",
Documentation.Source = "https://www.jaknapowerbi.cz . ",
Documentation.Version = " 1.0 ",
Documentation.Author = " Štěpán Rešl ",
Documentation.Examples = {
[
Description = " Input: ""ID"", ""Travel_Agent"",""DateKey"", [Travel_Agent], [DateKey] ",
Code = "",
Result = "150"
]
}
]
in
Value.ReplaceType(
output,
Value.ReplaceMetadata(
Value.Type(output),
documentation
)
)