--- title: "Aggregate Usage Data with Rules Engine" slug: "aggregate-usage-data-with-rules-engine" updated: 2026-11-23T12:31:41Z published: 2026-11-23T12:31:41Z canonical: "support.gainsight.com/aggregate-usage-data-with-rules-engine" --- > ## Documentation Index > Fetch the complete documentation index at: https://support.gainsight.com/llms.txt > Use this file to discover all available pages before exploring further. # Aggregate Usage Data with Rules Engine ## Introduction In this tutorial, we will use Rules in order to query for usage data related to page views and then pivot the data to aggregate it either by week or by month. This will be accomplished by creating a Dataset Task that queries the usage data within the MDA, and then creating a separate Dataset Task that pivots the data and completes the aggregation. Following are the goals we intend to achieve using a single rule: 1. Create Dataset to Fetch Data from MDA. 2. Create Dataset to Pivot on Pages data. ## Fetch Data from MDA 1. In this step, Navigate to ***Administration > Rules Engine*** and create a Rule that enables you to fetch data from MDA. ## Create Rule 1. Enter following details in the Create Rule page: - **Rule For**: Select **Company**. - **Rule Name**: Enter an appropriate name. - **Folder**: Select a folder for the rule. - **Description**: Enter description (optional). - Click **NEXT**. *Setup Rule* page appears. ![clipboard_e967a76f48b7b6541c91afef51d032b40.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/clipboard_e967a76f48b7b6541c91afef51d032b40.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=CR%2BIxyhORUIkYXlCSzaiFx0KK8YrEED6kOmpwLVNJ3Q%3D) ## Setup Rule 1. In the **Setup Rule,** click **DATASET** in order to begin creating the tasks the rules will need to complete. ![clipboard_e47f249860d2f2110a0f7969fcd63e5c9.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/clipboard_e47f249860d2f2110a0f7969fcd63e5c9.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=ke9Ev4opQrpJcPbR0Zs0rHsjRTkE9yxGlq8LfhTAqxc%3D) 2. Set a **Task Name** and an **Output Dataset Name** for your Dataset Task. The **Task Name** will be used to identify the task within the rule, while the **Output.** **Dataset Name** will be used to identify the resulting dataset after the task is completed. Gainsight recommends adding a **Task Description** with more details about the dataset. In our example, this task will fetch data from the MDA and then pivot on the Page Name; so we have named the task, its description, and its output dataset name, accordingly. 3. Click **SAVE**. ![Name the Dataset.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Name_the_Dataset.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=sOYJlgwfFELQ9FDk7ltQMRJlESYL9aDpLeesrWUMkgI%3D) 4. Since the goal of this rule is to fetch data from the MDA, select the object that you previously uploaded your **Usage Data** into. 5. Add the fields that you would like to reference as part of the pivot and the aggregation and add them to the **Show** section. In our example, we’ve selected the example object **Usage Data**. In the Show section, we’ve added the fields Company and Company Name (in order to tie this data back to those records). We’ve also added **Date Field**, **Page Name**, and **Views** as those will be necessary fields for the Pivot and Aggregation. ![Configuring Dataset for Pivot task.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Configuring_Dataset_for_Pivot_task.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=NF4vPP45%2FjdHit%2FxcOZQVsvkujr%2B3BoSV0uxO%2B6Awi4%3D) **Note**: While not necessary to complete this tutorial, each Dataset Task also has a section for exporting the resulting data to the S3. For more information on the options presented, click [here](/v1/docs/export-to-s3-from-rules-engine). Select the exporting option that works best for your team. 6. Click **SAVE** in the top-right to save the task. ## Pivot on Pages Data 1. Go back to the **Setup Rule** and click **+TASK** in order to add a new Dataset Task and Select **Pivot** to complete pivot and aggregate the usage data. ![Select Pivot task.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Select_Pivot_task.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=rwxhn2HN%2FkKhiHCvofu76uh8FAVRPuQ0zLrx6RYDh0U%3D) 2. Enter the **Task Name**, **Task Description,** and **Output Dataset Name** for this task. Following example shows the Task Name and Output Dataset Name as this task is to pivot on page data and aggregate by date. ![Configure pivot task.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Configure_pivot_task.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=v4yrgn7ODjGol%2Fo8bkuJ4NjPYEFbmg69rkYyWEGalbQ%3D) 3. Under **Dataset,** select **Fetch from MDA** in order to pull in the data fetched by the previous task. Also add the fields **Date Field** and **Company** into the Show section, to give reference that data within the task. ![Configure pivot show section_1.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Configure_pivot_show_section_1.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=t3AlKgJ3Ajl3awgJVpvFfqnPMc4wrA8RV4UBbd5oCd0%3D) 4. Drag the **Page Name** field and drop it under the **Pivot On** section. The **Pivot conditions to evaluate** window is displayed. ![Pivoting on Page Name field.gif](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Pivoting_on_Page_Name_field.gif?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=qlvFDAZJn8Bg%2BGYciB%2BvJEocmnr28sl6ajXqBOrt7jo%3D) 5. Configure the conditions as shown below: 1. Values of the Page Name 2. Use the **Output Field Label** column to determine how the pivoted data will be identified, 3. **Aggregation** column to determine how the data will be aggregated. 4. **Field** column to determine what data will be selected as part of the pivot. 5. **Default Value** column to determine value of data that is fetched, but does not meet the pivot condition. Set this to **0**, to avoid views from other pages to throw off our aggregations. 6. In the following example, various aggregation methods are used on three pages: Click **+ADD** to add additional rows. ![Configure Pivot table_1.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Configure_Pivot_table_1.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=fiJ05MqI7gjuW1lJcOgaDEvvnc34aOm2atP8tb9RLCk%3D) 7. Click **OK** to set the conditions. In the **GroupBy** section, add **Date Field** and **Company Name** to ensure the aggregation successfully groups the data by time for each company. When you drag the Date field to Group By section, **Company Name** field automatically changes to **Count of Company** , in the Show section. You must change this aggregation and then drag and drop the **Company Name** field to **GroupBy** section. ![Group by Date field and Company Name.gif](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Group_by_Date_field_and_Company_Name.gif?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=pVTAZlGUds%2FU1e4LLy14%2FbElcXlk2HVDcj4g%2B003m2k%3D) 8. Click the gear icon on the **Date Field** in order to select how frequently you would like the aggregation to be grouped by. For weekly aggregation, select **First Day of Current Week** or **Last Day of Current Week.** For monthly aggregation, select **First Day of Current Month** or **Last Day of Current Month.** ![Summarizing Date field.png](https://cdn.us.document360.io/8e136619-829c-49c5-afb1-72de86f13288/Images/Documentation/Summarizing_Date_field.png?sv=2026-02-06&spr=https&st=2026-11-24T16%3A04%3A21Z&se=2026-11-24T17%3A04%3A21Z&sr=b&sp=r&sig=nWVdTro06z02Jla5eSNZOCGcIfd0513kNQDYSt2%2F8gU%3D) 9. Click **SAVE.** These actions aggregate page views successfully for each company either weekly or monthly. You can then setup any action on this data in the **Setup Action** page. For more information on how to set rule actions, check the article [*Setup Rule Action Types*](https://support.gainsight.com/gainsight_nxt/03Rules_Engine/Rules_Engine_(Bionic_Rules)/Admin_Guides/06Setup_Rule_Action_Types).