Of course! This is a classic and very useful pattern in Power Pivot. You want to create an aggregate flag based on a group.
The best way to do this in Power Pivot is with a Measure. A measure is a dynamic calculation that responds to the context it's placed in (like the rows of a PivotTable).
Here is the DAX formula you need, along with a step-by-step guide.
The Short Answer: The DAX Formula
The simplest and most efficient DAX formula for your measure is:
Has Support Activity := MAX('data'[is_support])
Why this works:
In DAX, when dealing with a Boolean (TRUE/FALSE) column:
TRUE is treated as 1
FALSE is treated as 0
The MAX() function will look at all the is_support values for a given tax_id in your PivotTable.
- If there is at least one
TRUE (i.e., at least one 1), the maximum value will be 1, which DAX displays as TRUE.
- If all values are
FALSE (all 0s), the maximum value will be 0, which DAX displays as FALSE.
Step-by-Step Guide to Create the Measure
-
Open the Power Pivot Window: In Excel, go to the Power Pivot tab and click Manage.
-
Create the New Measure:
- In the Power Pivot window, make sure you are on the
data table tab.
- Go to the Home tab, click New Measure. (Alternatively, you can click in the calculation area at the bottom of the grid).
-
Enter the Formula:
- A dialog box will appear.
- Measure Name: Give it a clear name, like
Has Support Activity.
- Formula: Enter the DAX formula:
=MAX('data'[is_support])
- Category/Formatting: You can leave these as default for a TRUE/FALSE value.
- Click OK.
How to Use It in a PivotTable
- Go back to your Excel sheet and insert a PivotTable from your Data Model.
- From the PivotTable Fields list, find your
data table.
- Drag
tax_id to the Rows area.
- Drag your new measure
Has Support Activity to the Values area.
Your PivotTable will now look exactly as you described:
| Row Labels (tax_id) | Sum of Has Support Activity |
|---|
| 11111 | TRUE |
| 22222 | FALSE |
| 33333 | TRUE |
| ... | ... |
How to Create the Display Folder
You mentioned wanting a "folder" for your measure. In Power Pivot, this is called a Display Folder, and it's great for organizing your calculations.
-
In the Power Pivot window, go to the Home tab and click on Diagram View.
-
Find your data table in the diagram.
-
Right-click on the new measure you created (Has Support Activity) and select Create Hierarchy. This is a quick trick to open the properties pane. You can just delete the hierarchy later.
-
In the Properties pane on the right, find the Display Folder field.
-
Type the name of the folder you want, for example, Support Flags. Press Enter.
Now, when you go back to your PivotTable Fields list in Excel, you will see a folder called "Support Flags" containing your measure, keeping everything neat and tidy.
Alternative: Calculated Column
While a measure is highly recommended for this task, you could also use a calculated column. This would pre-calculate the value for every single row in your table. You would only do this if you need to use the TRUE/FALSE value as a slicer or on the rows/columns of a pivot table itself.
The formula for a calculated column is different because it needs to create its own context.
= CALCULATE(
MAX('data'[is_support]),
ALLEXCEPT('data', 'data'[tax_id])
)
Recommendation: Stick with the Measure approach. It's more efficient, uses less memory, and is the standard way to perform aggregations in Power Pivot.