Grouping by and summing in Excel - excel

I have a table in Excel that consists of two columns, Name and Score. The Name column is not unique, many names appear several times. I want to create another table that using formulas groups by name and calculates the total score for each.
So if James had 3 records with scores 2, 8 and 4, the other table would show James with total score 14. How do I do this?

You need to create a pivot table. Select the data you want to use and then go to the Insert tab on the ribbon and select Pivot Table. After the pivot table is created you need to add the Name column to the Rows section of the pivot table and the Score column to the Values section. Then change the Values calculation from count to sum.

Related

Pivot Table distinct count of employees

In Excel I have raw data that looks like this:
I am creating a pivot table that lists employees and the days they punched in by department / shift.
I'd like the Employee Count to give a count of the distinct number of employees in the particular Department / Shift. Currently the pivot table is showing a count of the total number of rows in which each employee appears.
Instead of 1st SHIFT Warehouse 44th having a total of 69 I want it to have a total of 5. And no values alongside the individual employee rows. When I change Count to Sum I get values of 0.
How can I achieve this?
When creating the pivot table, check the box for "Add this data to the data model". Then design your pivot table, doing on a count on employee. Lastly, right click on the employee count in your pivot, go to Value Field Settings, and change your Summarize to Distinct Count.

How do I create a custom grand total or calculated field in my pivot table in Excel?

I have a pivot table with various calculated fields. I want one of these calculated fields to change depending on what I choose from the slicer. In order to help understand what I'm trying to do I can provide some screenshots:
Here each row contains information for one SITA and each column is a calculated field. The Var(%) column is (ABS(OTB Occupancy - OFF Occupancy))/OTB Occupancy. The very last entry in Var(%) is calculated manually and takes the average of the column (this restricts me from filtering the pivot table as I'll have to recalculate the formula and/or move it to another cell so it stays in the position where it is the last cell).
Now my problem is I am no longer using this pivot table but I am starting to create other pivot tables which need to be more dynamic than this one. For example:
As you can see the first two entries of April in the pivot table correspond with the previous pivot table (OTB Occupancy and OFF Occupancy are the same as Sum of Act_Occ and Sum of Fct_Occ respectively). However, I need the third column to be the average given in the last entry of Var(%). (Please note that this cell isn't part of the pivot table and it's just a formula i used). But also, if I were to select two SITAs only from the slicer I'll want only the average of them two.
I'm not sure if excel can do what I want but any help is appreciated.

Why pivot table does not show identical rows from the initial table?

Why pivot table does not show identical rows from the initial table? My expectation is that the pivot table could show these in separate rows.
The initial table has 100 rows and my pivot table (while taking 4 columns) showing less.
To be more specific: All cells in 3 columns out of 4 are formatted as text, 1 column as number. If there are two rows which are identical in all 4 columns why only one of these is shown in the end pivot table? The number column is not summarized.
Identical values in the rows of a pivot table will be rolled up into one row. If the number is in the values area of the pivot table, it will be summarized.
See this data example:
If the number column is in the Values of the pivot table, then the data gets summarised and only three rows of text are showing. It is entirely possible to rename the column title from "Sum of ..." to something else, so it may not be apparent that the data is summarised.
If you want to show all data, then put the number column into the rows area. You can then format the pivot table to repeat all item labels if you want to see the text for all rows.
Edit: If all values in the Rows area identical, then the data will be rolled up, too. A pivot table is about summarizing data. You'd typically have something in the values area that calculates something about this unique combination of four values.
If you want to show all duplicates, you need to enter a unique 5th column in the row area.

Excel Slicers for Measures

I have a cube with two measure(count of patients) and (distinct count of visits) , and various dimension(date,program,region,etc), when I browse the cube data from excel, I can choose all the dimensions in the slicer, but my question is is there anyway i can choose the measures in the slicer? From what I see, when I insert a slicer I only get to pick the dimesnions
Any help would be appreciated
I'm not sure of a way around using PowerPivot to do this, short of complicated VBA scripts.
To do it with PowerPivot:
Create a new table with two columns. Column 1 contains the name of your measures and column 2 contains an index for each. e.g.
and add this to the Data Model (but don't create any relationships to any other tables).
Create a new measure with a SWITCH function that has the same relationship between the measures and their values in the Index column, e.g.
[Chosen Measure]:=SWITCH(TRUE, MIN(MeasureTable[Index])=1, [DistinctPatients], MIN(MeasureTable[Index])=2,[DistinctDates])
Add the new measure to the values section of the pivot table and add the
Measure column from your new table to BOTH a slicer AND the column headings in the pivot table and remove the row and column totals.

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.

Resources