Group By Keys
The Group By Keys component is a powerful data organization tool within the Nappai automation system. Its primary purpose is to simplify and structure your data by grouping records together based on shared values.
Imagine you have a long list of customer orders. Instead of looking at every single order row-by-row, you can use this component to group all orders by Customer Name. This transforms your flat list into a structured summary where each customer appears once, and all their order details are collected into a single, organized list. This makes it much easier to analyze trends, prepare reports, or feed data into other systems that require grouped data.
How it Works
This component works by analyzing your input data and identifying unique combinations of the fields (keys) you select.
- Scan: It looks through your dataset and identifies distinct groups based on the “Grouping Keys” you specify.
- Collect: For each unique group, it takes all the other fields in the data (fields that are not keys) and collects their values into a list.
- Output: It creates a new dataset where each row represents one unique group. The key fields remain as simple values, while the other fields are now lists containing all the data points from the original rows that belonged to that group.
Simple Example:
If you have a list of sales records with fields City, Salesperson, and Amount, and you choose City as your key:
- The component groups all rows by
City. - The output will have one row for “New York,” one for “London,” etc.
- For the “New York” row, the
SalespersonandAmountfields will contain lists of all the salespeople and amounts associated with New York.
Connection & Credentials
This component does not connect to external APIs or services and does not require any credentials. It processes data directly within the Nappai environment.
Inputs
The following fields are available to configure this component.
-
Data: [DataInput] The dataset containing the records you want to group. Each record should contain the specified group keys.
- Visible in: All configurations
-
Group Key(s): [REQUERIDO] [StrInput] A comma-separated list of field names to group by (e.g., country,city).
- Visible in: All configurations
-
Aggregated Field Name: [StrInput] The name of the new field where the grouped list of remaining data will be stored.
- Visible in: All configurations
Outputs
- Grouped Data: [Any] The resulting dataset where records are organized into groups. Each record represents a unique combination of the group keys, and non-key fields are aggregated into lists.
Output Data Example (JSON)
json { “Grouped Data”: [ { “City”: “New York”, “SalesTeam”: [“Alice”, “Bob”], “Amount”: [150.00, 200.00], “Aggregated_Field”: [ { “Salesperson”: “Alice”, “Amount”: 150.00, “Status”: “Completed” }, { “Salesperson”: “Bob”, “Amount”: 200.00, “Status”: “Pending” } ] }, { “City”: “London”, “SalesTeam”: [“Charlie”], “Amount”: [300.00], “Aggregated_Field”: [ { “Salesperson”: “Charlie”, “Amount”: 300.00, “Status”: “Completed” } ] } ] }
Connectivity
This component is typically used in the middle of a workflow, after data has been fetched or extracted from a source (like a database or CSV file) and before it is prepared for final reporting, visualization, or sending to other applications.
- Connects To: It usually connects to components that require structured or summarized data, such as:
- Table View components: To display grouped summaries.
- Data Export components: To save organized data to a file.
- AI/LLM nodes: That need contextual lists of data for analysis.
- Email or API triggers: That need to send grouped notifications or requests.
Usage Example
Scenario: You are automating a monthly sales report. You have a dataset of individual sales transactions.
- Input: Drag and drop your sales dataset into the Data field.
- Configure Grouping: In the Group Key(s) field, enter
Region, Product. This groups all sales by Region and Product. - Configure Aggregation: In the Aggregated Field Name field, enter
SalesDetails. This will create a new field containing all the details of each transaction for that specific Region/Product combination. - Output: The output Grouped Data now contains one row for each unique Region/Product pair. You can now easily see which products sell in which regions and view all the associated transaction details in one place.
Tips and Best Practices
- Choose Keys Wisely: Only include fields in the Group Key(s) that you want to use as the “identity” of the group. If you include too many keys, you might end up with many small groups. If you include too few, you might group unrelated data together.
- Understand Aggregation: Remember that this component does not calculate sums or averages. It collects the original values into lists. If you need totals, you will need to add a subsequent component (like a Math or AI component) to process these lists.
- Field Names: Ensure the field names you enter in Group Key(s) exactly match the column names in your data source (case-sensitive).
- Data Types: The data in your key fields should be consistent (e.g., strings matching strings) to ensure accurate grouping.
Security Considerations
- Data Privacy: Ensure that the data you are grouping does not contain sensitive personal information unless you have the appropriate permissions and security measures in place. Grouping can sometimes inadvertently combine sensitive data points.
- Data Access: Verify that your Nappai user account has the necessary permissions to read the source data provided to this component.