I'm struggling to figure out the correct Excel data model relationship technique to link a slicer to a pivot table in a two-step process.
Here is my simple Excel file to download.
There are three fields in my example data: Person, Activity, and Cost. I want a way for users to pick an Activity (or multiple Activities) in the Activity slicer, and then show the full Cost and Activity data for any Person who does that Activity. Here is a screenshot of the data table (1.), and its full pivot table (2.). The output I desire is mocked up in (3.). It's basically a subset of (2.). The complication is that I want to show the full record (ie all Activities) for the Person, not just the Activity selected by the user in the slicer. So there's a relationship from Slicer Activity -> Person -> All Activities per person/
Screenshot of data and desired outcome
I can can easily break the process down into some simple joins and relationships, but I'm unsure how to implement the below in Power Pivot or Power Query. It must update the final table (Step 4) whenever the slicer is updated. I'm just not sure how to bridge from the Activity slicer to the Person table, and then from the Person table back to the source Data.
screenshot of data model stages
Can this be done simply in Power Pivot?
You are going to need to use the Data Model in Excel, with a Measure, to achieve this. Here is an overview of the steps, then followed by the detail.
Here are the steps:
1. Load table into PowerQuery
Table 1
and rename it to Activity
.Activity
(again on the left) and select Reference
. This will create a new query (table) based on the first.Activity Slicer
.Activity Slicer
, right-click on the Activity
column header and select Remove other columns
.Remove Duplicates
.Activity
(the same as in the spreadsheet); 2. Activity Slicer
- single column Activity
with distinct values.Close & Load
and select Close & Load To...
Import Data
window, select Only Create Connection
and at the bottom select (check) Add this data to the Data Model
.2. Create measure in the Data Model
Manage
(first one, with Data Model underneath it).Activity
tab, and then select any cell in the Calculation Area. If Calculation Area isn't visible, then select it in the ribbon.Total Cost:=
var persons = CALCULATETABLE(
VALUES(Activity[Person]),
ALL('Activity'),
TREATAS( VALUES('Activity Slicer'[Activity]), 'Activity'[Activity] )
)
var result = CALCULATE(
SUM('Activity'[Cost £k]),
FILTER(Activity, 'Activity'[Person] IN persons )
)
RETURN result
That's it - no relationships needed. Close the Power Pivot window and return to main Excel.
3. Create/add Pivot and Slicer
From Data Model
.
Insert Slicer
. Select the All
tab and you should see the tables from the Data Model. Select Activity Slicer > Activity
That's it - test!