-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfxAddRunningCount.pq
More file actions
27 lines (27 loc) · 913 Bytes
/
fxAddRunningCount.pq
File metadata and controls
27 lines (27 loc) · 913 Bytes
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
let
AddRunningCount = (dataTable as table, columnName as text) as table =>
let
// Step 1: Get distinct groups in original order
DistinctGroups = Table.Distinct(dataTable, {columnName}),
// Step 2: Add running count to distinct groups
IndexedGroups = Table.AddIndexColumn(DistinctGroups, "Running Count", 1, 1),
// Step 3: Merge running count back to original table
Merged = Table.NestedJoin(
dataTable,
{columnName},
IndexedGroups,
{columnName},
"RunningCountTable",
JoinKind.LeftOuter
),
// Step 4: Expand the running count column
Expanded = Table.ExpandTableColumn(
Merged,
"RunningCountTable",
{"Running Count"},
{columnName & " Running Count"}
)
in
Expanded
in
AddRunningCount