Insert subtotal for Excel spreadsheets - excel

I have some irregular data (e.g. I have 5 groups of data, each group occupies different amount of rows) and I am wondering if there is a way to use Python to add subtotal to all of my spreadsheets, breaking at each group change.
Since row amount is irregular for each group, I tried inserting empty row at each change and adding a subtotal. However, I am unable to do a sum for each change or a grand total without using hard code (specify on the row number, which changes for every spreadsheet).
Thanks in advance.
Edit: Added code I am working on
for num in range (8, ws.max_row+1):
if ws['E'+str(num)].value == ws['L1'].value:
ws['L'+str(num)]='=SUMIF($A$'+str(ws[num])+':$A$'+str(ws[ws.max_row])+',LEFT(A'+str(ws[num])+',6),$E$'+str(ws[num])+':$E$'+str(ws[ws.max_row])+')'
num+=1

Can you add a column to each list that can help you categorize them? that way you can do a =SUMIF based on the categorized names. here's a code snipit and an image to reference:
=SUMIF(B:B,B15,C:C)
the formula calculates the left table (dogs).
as you can see the totals wont be added if the category is mentioned. also, all three tables are irregular so it will add up regardless of length.

Related

Find, Sum, and Remove Duplicates in 3 different subsets of data in a spreadsheet

I have a spreadsheet that contains truck load data. The spreadsheet contains each portion of the delivery cycle; Month-Year, Supplier(VDH_Columns) to Vendor Pickup(VPK_Columns) to Receiver(CUST_Columns) and Tons delivered(Tons). If the Vendor Pickup Columns are populated, the cycle goes VPK to CUST. If the Vendor Pickup Columns are not populated, the cycle goes VDH to CUST.
I want to maintain the spreadsheet exactly how it is and not make a CUST sheet, VPK Sheet, and VDH Sheet.
The ultimate goal is to have 1 Month_Year for each Receiver(CUST) and sum either the VDH or the VPK. Below is a piece of the spreadsheet(What it looks like now) and I manually created what I want it to look like.Spreadsheet Example
I tried a pivot table with a Month_Year filter but the problem is that I can't see once I try to add all the other columns it becomes so busy that I end up quitting. I've thought about Consolidate but I have no experience with that. I'm assuming VBA code would be able to accomplish it but I have no experience there either.
Thanks for any help
A Pivot Table is the way to do this. You need to drag all of your columns to the "Rows" field, and then drag the Tons column to Values. It should automatically use a SUM summarization:
Then, you would select a Tabular layout from the Design tab.
This will give you the desired output:
You can get rid of the (blank) values by using Conditional Formatting on the Pivot Table. Use custom number format ;;;

How do you count the occurrence of same data set in two columns-set in excel?

How can we count the occurrence of each set of data? For eg I want to check how many time the customer country in column A comes alongside country in column B ie (How many times Australia-Australia occurs in column A and column B?). The result for unique occurrences are place in right hand side of the sheet. I have found out unique occurrences of the sets and want to count how many times each occur.
You asked for a formula, but a pivot table can do the same thing faster; and without requiring you to create the table for unique countries (option found under insert, usually the first button in the ribbon):
This is how it looks like after pulling the fields in the right 'boxes', the 'Tabular' report layout is selected and the subtotals turned off.
You can make 'Australia' repeat itself too under report layout if so you wish.
Again, SUMPRODUCT is your friend:
=SUMPRODUCT(--(($A$2:$A$11&$B$2:$B$11)=(D2&E2)))
You can use COUNTIFS function as below.
=COUNTIFS(A:A,D2,B:B,E2)
Adjust the ranges to suit your data and copy down.

Tableau: hide table calculation for only one column

I'm working on a visualization in Tableau, regarding numbers for actual figures, budgets, and estimates. For budget and estimate, I also want to show the percentage of difference compared to the actual. I have these numbers for several categories.
I recreated an example as below.
What I now want is: Hide the percentage calculation ONLY for the actuals column.
I tried several things. but it always ends in multiple columns being deleted. How can I do this?
(Percentages are calculated across table and based on "actual" scenario).
Edit 1: As in one of the answers, creating seperate calculated fields for each value is an option. But in my problem, I will have a lot of measures where I want to disply it this way. So creating 5 calculated fields for every measure is really a last option.
Also: I now solve it using 2 different sheets on the dashboard. One sheet with actual numbers, and one sheet with percentages (hiding the actual column). But then the line up is not so nice, and also when the sorting of the dimension changes, it is tricky. I have also options to drill down the hierarchy of a dimension, and with two sheets, one of the two will of course not adapt then.
Currently you are using F1 for rows and F2 for columns and measures that will split to as many values as F2 has (Currently their are 3 columns).
Solution that I can think of in this particular case is to remove F2 from columns part and create 5 formulas for the measures.
Actual Sum // Since we don't want Acutal (%diff) we won't create that formula
Budget sum
Budget (%Diff)
Estimate Sum
Estimate (%Diff)
Now formula will be like
If F2 = "Actual" //Same goes for Budget and Estimate
Then f3
End
Take one more sheet now add the quick table calculation for difference for Budget and Estimate and add those to Formula fields.
Now place all 5 formulas in columns part, So you have your measures.
To add the column headings you can use dashboard, Add the sheet to dashboard and manually add texts to the measures that will look like the one you have attached in screen shot.
I have implemented a sample using Sample super store and attaching the screenshot for the same.

Dividing a filtered subcolumn with grand total

Hey guys is there a more elegant solution to divide one column that is not a value field with a grand total. Below is a picture of what I have:
I want to have another column at the end of the pivot that will have cells from "Same" column divided by cells from Grand Total.
Here is what I tried:
Simply put =D5/E5 (D is column Same, E is column Grand Total) and autofill it down. This solution is messy because pivot will change its length
Tried with getpivotadata without success. All cells in calculated field end up having the same value.
Adding a calculated field. Problem with this is that the column SAME is not a value field offered, its just one of the values within grouping value field.
Adding another grouping into values of pivot, renaming it % and changing it to be a percentage of parent column. Problems here are 1-% of SAME isnt at the end of the pivot, 2- I get % of other columns belonging to grouping column which I dont want. 3- excel adds more text that i cant remove (count of grouping in each column) , 4- I am forced to hide excess columns and make whoever will be using the files prone to mistakes while doing vlookups and VBA.
I am using excel 2010.
Is there an easier way to solve this that keeps eluding me? Thanks

Excel pivot table exclude some column totals

I am using an Excel 2010 pivot table to display data. I need the sub totals in most columns but some columns display percentages and totaling the percentages is not correct and displays confusing values. Is there any way I can choose which columns not to total.
It's hard to make sure I'm accurately addressing your question without more detail about your data, but I will provide a simple example.
Recommendation
I would suggest that you put all measures/values in the Values area of the Pivot Table, and not in the Row Labels. That way, you will not get Row sub-totals for values.
In order to address the non-additive totals and sub-totals for your percentages, I recommend that you remove the pre-calculated percentages from your Pivot Table Values and instead use a Calculated Field that is calculated within the Pivot Table itself from the base data, and will provide correct aggregate totals and sub-totals.
Example
See below:
Method
In order to create a Calculated Field using the Ribbon, select your Pivot Table, and then go to PivotTable Tools --> Options --> Fields, Items, & Sets --> Calculated Field.
Then, enter a name for the new Field (CalcPercentSoldUnits in my example below), as well as the formula definition for the field ( =UnitsSold /UnitsProduced in my example below). Click 'Add' to create the field and then 'OK' to exit the dialog box.
Now you have created a derived field not in your base data table, but in your Pivot Table, which can be used just like a normal field. You can also see that it will calculate totals and sub-totals correctly because instead of adding constants, it is calculating based on the sums of other constants from which the percentages are derived.
In some cases depending on how your data is structured, you may need to create a Calculated Item instead of a Calculated Field.
I hope this helps - if this doesn't address your situation, please post additional examples of your data and desired results. Thanks!
I have the same problem. Some Columns should be totaled, and others should not be. The only thing I figured out is to Grand Total all columns, then format those cells in the Grand total so that the font color matches the background color. This hides those selected Grand Totals from being viewed and/or printed. I experimented by expanding the Pivot Table rows, and the formatting for the selected cells followed into the new cell(s) and when I removed some of the rows, the formatting followed as well.
Wherever you don't want to show the total columns simply hide the column in the total section. I couldn't find any other way to do it.
Be careful about things like distinct/unique counts. This method helps with percentages, but you don't want to sum or average or otherwise aggregate unique counts. I would prefer to be able to just exclude a total for a single field but haven't found a method to do so.
I think I have a similar situation and a great answer for presentation purposes. I'm billing a customer for unbilled items; my pivot shows Qty, rate, and total missed revenue (qty*rate) for each month. Having a sum of Qty and Revenue makes sense for each month, but totaling the rates of the items doesn't. Pivot table and value options are an all-or-none solution. Rather, I just selected the totals I needed to hide and formatted them with white font color (blue for the grand total). My pivot table looks great now with this band-aid approach.

Resources