Excel pivot table "Distinct Count" not compatible with Group for dates? - excel

Using Excel 2013, I need a pivot table which:
Counts unique values in a field ('Distinct Count')
Groups the data by Year and Quarter
If I create the pivot table by checking "Add this data to the Data Model" then the "Distinct Count" option is available as expected. However, I cannot group my date columns (both Group and Ungroup are grayed out), making the report unusable.
OTOH if I don't check "Add this data to the Data Model" when I create the pivot table, Grouping dates works fine but I lose the "Distinct Count" option as expected. Exact same data with date column formatted as short date.
Can someone verify and/or enlighten me about the reason?

Correct: the grouping feature is not available in Pivots based on the Data Model, and the Distinct Count feature is not available on 'traditional' pivots. But you can either use formulas on your source data to add the groups there, and pivot that field, or use DAX formulas to create groups within the Data Model.

Related

Combining Column Values in an Excel Pivot Table

In order to simplify a stacked bar chart, I am looking to sum up the counts of multiple columns I have in my pivot table. For example, in this sample table, I would like to combine Fruits and Vegetables into one column, so that each bar will comprised of three colors: one for Meats, one for Grains, and one for Fruits+Vegetables.
Pivot Table and Stacked Chart
For reference, this is the data source:
Data Source table
I tried adding a Calculated Field, but I'm not sure if I can use specific values from a column in the Formulas field. Is there a way to create something like this from a pivot table, or should I be taking a different approach to this all together?
I'm using Excel 2016, -- pretty sure it's the same with older versions, but the premise is the same.
In your pivot table, Select the Pivot Table Tools> Analyze tab, then "Fields, Items",then pull down to"Calculated fields". Enter a name for the generated field, and the formula you want to use:
In my example, I added the fields Fruit and Vegi's from my available pivot table fields (which is based on my data table).
Then select the calculated field as you would any other..
and create the chart as usual.
Hope this helps.

Ignore tier 1 rows in Excel pivot tables

I have a pivot table in Excel, and I'm trying to do some calculations on the results. This is all fine and good, but I'm running into a problem due to the grouping of a pivot table.
I have a dataset indicating transaction history for a particular client/patient at a vet clinic. These are reflected by clientID and patient name in my pivot table. I've used a pivot table to group by client then patient to see when the first purchase was made and how many total purchases there have been. I want to then do a calculation on that for each patient.
My problem is here. Excel has all the data for each client grouped in what I'll call "tier 1 results". The only data I want to do the calculation on are the "tier 2 results". These are row 7 and then rows 8-9 in the screenshot below.
In effect, I wan to include something in the equation in column F to ignore any bold text, but Excel doesn't appear to be able to do this. VBA is an obvious solution for me, but I'm creating steps for salespeople to use to analyze the data while they're out in the field. We need to keep things as simple as possible. Copying and pasting an in-cell equation is one thing, but using VBA is way over their heads.
Any thoughts on how to ignore the tier 1 results?
Your pivot table uses compact form layout, where all the groupings appear in one column. You can change that to tabular form to have each group level in its own column. The screenshot shows the difference:
Click a cell in the pivot table and then Pivot table Design ribbon > Report Layout dropdown > Tabular form. There are other settings to get rid of subtotal rows, etc.
Now you can build formulas that take into account only the level that you require. (It is also possible to repeat the pivot group labels for each group level where there are blanks.)

Excel pivot table - average of calculated sums

I'm sure this is simple, but how do I get a pivot table to display an average for a calculated sum of fields? In the simplified example, I've filtered out fund x1, and the pivot table is showing the sums of the remaining funds per person. Now how do I get an average by person (so, manually calculated, 3300/3)?
I tried using a calculated field, but cannot figure out how it will work because the denominator will change based on how many people will have the funds I'm filtering on. If I use the averaging inside the calculated field it goes back to averaging the funds.
I tried putting the calculation outside the pivot table, and this works, but of course as I filter, my calculated field is no longer adjacent to the pivot table data, instead just floating off on the worksheet by itself.
TIA.
Per request here is the field list - if I try adding an "average of amount" to the value box it averages the fund amounts, instead of the fund amount per person. :
Here is a working solution:
Firstly you should install or enable Power Pivot. Quoting Microsoft:
Power Pivot is an Excel add-in you can use to perform powerful data
analysis and create sophisticated data models.
https://support.office.com/en-us/article/Power-Pivot-Powerful-data-analysis-and-data-modeling-in-Excel-a9c2c6e2-cc49-4976-a7d7-40896795d045?ui=en-US&rs=en-US&ad=US
In newer Excel versions Power Pivot is already installed and you can enable it by going to:
File > Options > Advanced > Data > Enable Data Analysis add-ins: Power Pivot, Power View, and Power Map
Alright, so you have Power Pivot now and you can see Power Pivot tab. Please follow the steps below:
Select your data and click add to “data model” icon on Power Pivot tab.
In Power Pivot window add column which will count distinct number of
persons in the data. =DISTINCTCOUNT([person]) name it for example
“DistPersNo”. This is crucial step – Power Pivot enables you to
count unique values in selected column.
Add another column with formula =[amount]/[DistPersNo] name it
“PersonAverages”.
In Power Pivot window click PivotTable and add new pivot table to
your worksheet.
In Pivot Table add 'persons' to rows and 'amount' to values. Now, if you add 'PersonAverages' to values (sum of it) and filter out fund 'x1' you will achieve desired result i.e. value of 1100.
Hope that helps.
I would add a helper column in column D to count unique customers.
Sort your data by person
In column D2 put =IF(A2=A1, 1, 0) and call the column UniqueCust
Copy formula down your dataset for all rows
Add the column to your pivot
Create a formula in your pivot table called Avg per Cust =Value/UniqueCust
This will flag each row in your data with a 1 if it is the first time a name appears in the column or zero otherwise. The pivot table calculation will sum up the total value and divide by the total unique customers.
I'm assuming that you want the value to come in any pivot table and not in a cell calculated outside the pivot table as a formula.
As a workaround you can use another pivot table, which takes the input as the original pivot table to find the average.
pivot tables
The second pivot table has data source as- E3:F5 or till whatever row you require.
You'll have to refresh all so that the second pivot table reflects any changes in the filter of first pivot table.
I've hidden (or you can filter it out) the grand total in the first pivot table so that the average gives the average of the sum of the amounts.
Since you didn't mention how you are using the data, I will give a couple of options that could work.
If you are the only user of the data or if someone else using the data is pivot table savvy you can use the following field list setups to switch data usage:
Sort by Fund (Note the Fund and Person in the Row labels section)
and Sort by Person (Note the reversed position of Fund and Person in the Row labels section)
To simplify the data, you can always minimize the main fields.
If you are distributing the pivot table to other people who aren't able or willing to modify the pivot table data, I would recommend setting up two separate pivot tables (using the same data source) with the same setups that I showed above.
Click the pivot table to bring up the field list.
In the Values section where it says "Sum of Amount" click the drop down.
Click "Value Field Settings" and choose average from the list in the pop-up.

Excel 2007 Pivot Tables Custom calculation?

Again I'm wrestling with Excel 2007! I have some data I'm using to generate a Pivot Table and I'd like to divide all of the data by 1000...
I know I could go in and change the original data by hand but I'd much rather have a formula in the Pivot table itself that does this for me.
Any thoughts?
ps: You guys are awesome!
Create your pivot table, then in the Pivot Table options select Formulas/Insert Calculated Field. Assuming your data field is named MonthlySum then the formulat would be =MonthlySum/1000. Change the name of the Calculated Field as desired. The newly named calculated field will now be available to add to the values in your Pivot Table. As a side note you cannot use calculated fields as row labels.

Excel pivot table using date column to filter results

I have a Pivot Table which I have entered a date field into the Page Fields area to filter the data in the page.
However, I only have the option to select individual dates.
I want to use a date range. How can I do this? Or Can I do this?
Here is a classification by data source of how you can get / use the
Analysis Services
If you are using Analysis Services data, then I think you a breakdown of a date structure (if the dimension and the field is classified as such) by default.
(Hidden) Excel Sheet Data Source
Date Structure breakdowns are not readily available for data from another (usually hidden) sheet in the workbook.
You will have to create additional columns that mark ranges and then you can use it.
For example, lets say you have a SalesDate column. In your source, you should break the column further down so you get the the following columns
SalesDate
SalesYear
SalesQuarter
SalesMonth
SalesWeek
Then you can use these to effectively create ranges. If you have custom ranges you can put them here as well.
External SQL Query
If you are using a SQL Query, you can create computed columns that do these calculations for you. If you have the ability to modify the SQL Query, you can add the columns to the query.
In case you don't have the ability to modify the SQL, you can create Calculated field in the Pivot Table structure.

Resources