Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Using filters in aggregate functions

From: Excel 2010: Pivot Tables in Depth

Video: Using filters in aggregate functions

When you create a measure using an Aggregate function, PowerPivot calculates that measure's value for every row summarized in the PivotTable field. You can filter your PivotTable to limit your data but if you find yourself creating the same filter many times, you should consider creating a measure that incorporates that filter into its formula. In this movie, I'll show you how to do exactly that. So, we will jump into PowerPivot, clicking the PowerPivot tab on the Ribbon and the PowerPivot Window button, and we will create a measure that includes the filtered formula.

Using filters in aggregate functions

When you create a measure using an Aggregate function, PowerPivot calculates that measure's value for every row summarized in the PivotTable field. You can filter your PivotTable to limit your data but if you find yourself creating the same filter many times, you should consider creating a measure that incorporates that filter into its formula. In this movie, I'll show you how to do exactly that. So, we will jump into PowerPivot, clicking the PowerPivot tab on the Ribbon and the PowerPivot Window button, and we will create a measure that includes the filtered formula.

So to do that, we will click the PivotTable button to create a PivotTable andwe will put it on the new worksheet in Excel and click OK. Now remember that we need to use an Aggregate function such as SUMX for the filter to work. So, I'll create a new measure and I'll name it LargerOrders, and I will go down to Formula box. In an Aggregate function, you have the name of the function followed by the table and then the expression.

And the table argument can be a real table or it can be a virtual table that's created using another function, and in PowerPivot you can use the Filter function to create a virtual table that's a subset of the original table. To give you an example, I'll create the formula =sumx(Filter( and now the Filter function takes two arguments: the table that you're referring to and then the actual filter.

In this case, the table's name is Data. Type a comma and now I create a rule that does the filtering. And in this case, I only want to see orders with quantities greater than 18, so in other words 19 or more items. So, for that I will type in Data, a square bracket, and then we are referring to the quantity field so I will type a Q then a Tab to accept that field then a greater than sign and then the number 18. Now I type a right parentheses to close the Filter function and now I'm back in the SUMX function.

Now I will type a comma and now I can type the expression. So, first we'll have the data quantity field. So Data, left square bracket, q for quantity, press Tab, and I'm going to multiply that by the price field. So type an asterisk then data, left square bracket, and p for price. It's the highlighted items so I can press Tab to accept it then a right parentheses. And the formula looks good, so I can click OK.

So, you can see from the body of the PivotTable that the total of my larger orders appears in cell B4. Now, let's compare that to the total of all orders. So, to do that, I will drag the OrderTotal field to the Values area and you can see that the OrderTotal is greater than LargerOrders. The opposite function of the Filter function is called ALL and that ignores any filters in the data model or in the PivotTable. To illustrate that, I'll create another new measure and I will name this one AllStoreSales. Then in the Formula box I will create the formula SUMX. Again we need to use an Aggregate function, left parentheses, the keyword All, then a left parentheses, and then I want every row in the data table so I will type Data, right parentheses, a comma, and now I can type my expression, which will be once again that the Price field times the Quantity field.

So, Data, left square bracket, quantity, type q, and then Tab to accept the highlighted field, asterisk, and then data, left square bracket, p for price. It's highlighted, press Tab to accept it, then a right parentheses, and click OK. When I do, Excel adds that field to the data area of the PivotTable. Now, we will see what happens when I create a report filter based on the StoreID field. So, I'll drag the StoreID field down to the Report Filter area and then I will go up and click the Filter arrow.

Click the expand control next to All and then I'll check the Select Multiple Items box, clear the check box next to All, and then we will just look at the values for Store 1. So, I will click OK and Excel filters the PivotTable. So, you'll notice that the LargerOrders field changed its value, the Sum of OrderTotal field changed its value, but the AllStoreSales field did not change its value and that's because the measure used to produce its value ignores any filters applied to the table.

Building a filter into an aggregate function saves you time when you summarize data in PowerPivot. Be sure to name any filtered measures clearly to assure your PivotTable summarizes exactly the data you want it to. Alternatively, if you always want to measure to display the total of every row in the data model, use the All function in your measure's formula.

Show transcript

This video is part of

Image for Excel 2010: Pivot Tables in Depth
Excel 2010: Pivot Tables in Depth

66 video lessons · 39305 viewers

Curt Frye
Author

 
Expand all | Collapse all
  1. 1m 38s
    1. Welcome
      55s
    2. Using the exercise files
      43s
  2. 38m 8s
    1. Introducing PivotTables
      4m 2s
    2. Formatting data for use in a PivotTable
      4m 31s
    3. Creating a PivotTable
      4m 20s
    4. Pivoting a PivotTable
      3m 47s
    5. Configuring a PivotTable
      3m 23s
    6. Connecting to an external data source
      3m 30s
    7. Connecting to an Access database
      2m 11s
    8. Consolidating data from multiple sources
      4m 37s
    9. Updating and refreshing PivotTable data sources
      4m 21s
    10. Managing PivotTables
      3m 26s
  3. 23m 33s
    1. Adding, removing, and positioning subtotals and grand totals
      3m 27s
    2. Changing the PivotTable data field summary operation
      4m 35s
    3. Summarizing more than one data field
      3m 16s
    4. Creating a calculated field
      2m 27s
    5. Grouping PivotTable fields
      3m 17s
    6. Using PivotTable data in a formula
      4m 47s
    7. Drilling down to the underlying data
      1m 44s
  4. 28m 9s
    1. Sorting PivotTable data
      2m 0s
    2. Creating a custom sort order
      2m 48s
    3. Filtering a PivotTable field by selection
      2m 59s
    4. Filtering a PivotTable by rule
      2m 56s
    5. Filtering a PivotTable using a search filter
      3m 10s
    6. Filtering a PivotTable using slicers
      4m 2s
    7. Formatting slicers
      3m 43s
    8. Filtering a PivotTable with report filter fields
      5m 2s
    9. Clearing and reapplying PivotTable filters
      1m 29s
  5. 15m 2s
    1. Applying a PivotTable style
      5m 5s
    2. Creating a PivotTable style
      4m 37s
    3. Changing the PivotTable layout
      3m 20s
    4. Changing the data field number format
      2m 0s
  6. 24m 33s
    1. Highlighting cells by applying a rule
      2m 54s
    2. Highlighting the top or bottom values in a PivotTable
      3m 30s
    3. Formatting PivotTable cells using data bars
      3m 50s
    4. Formatting PivotTable cells using color scales
      3m 40s
    5. Formatting PivotTable cells using icon sets
      2m 45s
    6. Editing conditional formatting rules
      2m 15s
    7. Controlling how multiple rules are applied
      3m 28s
    8. Deleting a conditional formatting rule
      2m 11s
  7. 24m 0s
    1. Creating a PivotChart
      3m 29s
    2. Pivoting a PivotChart
      3m 5s
    3. Filtering a PivotChart
      3m 45s
    4. Formatting a PivotChart
      3m 35s
    5. Changing a PivotChart layout
      3m 14s
    6. Changing a PivotChart chart type
      4m 30s
    7. Adding a trendline to a PivotChart
      2m 22s
  8. 9m 27s
    1. Printing a PivotTable
      4m 2s
    2. Printing each item on its own page
      3m 30s
    3. Printing a PivotChart
      1m 55s
  9. 13m 30s
    1. Recording and reviewing a macro
      4m 10s
    2. Running a macro
      5m 57s
    3. Creating a simple PivotTable presentation kit
      3m 23s
  10. 19m 17s
    1. Introducing PowerPivot
      2m 9s
    2. Downloading and installing PowerPivot
      2m 36s
    3. Importing PowerPivot data
      3m 14s
    4. Managing table columns
      4m 1s
    5. Adding tables to a PowerPivot model
      2m 27s
    6. Creating relationships between tables
      4m 50s
  11. 24m 30s
    1. Introducing the DAX language
      2m 58s
    2. Using DAX operators
      4m 44s
    3. Surveying DAX functions
      2m 40s
    4. Adding calculated columns and measures
      4m 22s
    5. Using aggregate functions
      4m 24s
    6. Using filters in aggregate functions
      5m 22s
  12. 59s
    1. Additional resources
      59s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Excel 2010: Pivot Tables in Depth.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.