Professional Documents
Culture Documents
Oup The Elusive Fifth Parameter Explained
Oup The Elusive Fifth Parameter Explained
DID YOU
KNOW?
Introduction
The 'Table.Group' function is a powerful data aggregation and
transformation function. Let's start with a quick review of its syntax.
For a more comprehensive exploration, you can quickly navigate to
my earlier post by scanning the QR code depicted below.
Function parameters:
table: the table to group
keyColumns: a list of column names to group the data by
aggregationColumns: a list with aggregation operation lists
groupKind: an enumeration, by default set to GroupKind.Global
(null or 1) to ensure unique keys are returned
comparer: a comparer function to adjust grouping
Table.Group( myTable,
{"myKeyColName"},
{
{newColName, operation, type},
{..}
},
optional groupKind,
optional comparer
)
Sample dataset with mock transactions
Transfer this code into a new blank query to try it yourself or work along.
let
Source = Table.FromRows(
{
{#date(2023, 2, 5), "CloudBliss Shopping", -30.99},
{#date(2023, 2, 5), "Grocery Store",-15.5},
{null, "Nature's Pantry", null},
{null, "Card number 564", null},
{#date(2023, 2, 5), "PowerPro Utilities", -90.0},
{null, "Period: January 2023", null},
{null, "Account: 123456789", null},
{null, "Reference Number: RST-7890", null},
{#date(2023, 2, 6), "Gourmet Bistro", -75.50},
{null, "Date: February 6, 2023", null},
{null, "123 Main Street, Anytown", null},
{null, "Card number 564", null},
{#date(2023, 2, 6), "TrustWise Bank", -150},
{null, "ATM cash withdrawl", null},
{null, "Location: 456 Oak Street, Anytown", null},
{null, "Card number 843", null},
{#date(2023, 2, 6), "HappyTimes: WDR-789012", 5}
}, type table [Date=date, Details=text, Debit=Currency.Type]
)
in
Source
The task: Combine all Details per transaction.
Depicted below, the first 10 rows from our sample dataset.
The goal is to return a single record for each transaction. Combining all
the data that is in the Details column (optionally also aggregating Debit)
Returning a table where the first 4 rows look like this:
The User Interface is there to assist you!
We can quickly generate the bulk of the syntax by leveraging the UI.
Here are the steps I am taking:
One more thing to do: modify the grouping with a custom comparer.
We need to specify a fourth argument to be able to set the fifth.
Therefore, between the last }, and ), enter a comma, a null, and
another comma.