Explanation: https://www.youtube.com/watch?v=j3Cau-qmSwk
Note: Yes I know it's possible with VBS. But I'm convinced it can be done using some more or less standard Excel features. I simply want to learn more of those features by solving this problem and this is what that bounty is about.
Example: https://drive.google.com/file/d/1s4IvVe-jiHmvlij8Zv0HWLYFzsCV_4nz/view?usp=sharing
Short explanation:
On the second Sheet ( Named Graph ) is what I want to achieve.
Prices for hosts A, B and C are generated by changing number of files on the first Sheet ( Named Prices )
Longer:
I have a graph that compares prices from a few different hosting providers.
Each one calculates it's price based on a few different factors.
For example one charges for views other charges for GB storage other for Transfer. I've brought them to a common denominator "a file number" so when I change a value in a "file" cell all of the prices change accordingly for each hosting provider.
I would like to present that on a graph.
That would give me a better understanding how each one of those hosting providers would scare overtime.
Do I have to input into the file cell 50,100,200,400 copying those prices each time onto the other sheet of is there a better, easier or maybe even more dynamic way to approach this?
Thanks
One solution is to use the following formula:
=(Prices!B$2*$A2*Prices!$B$8)+(Prices!B$3*Prices!$B$7*Prices!$B$8)+(Prices!B$4*Prices!$B$7*$A2)
In your "Graph" sheet, cell B2, where you have the table laying out the values, simply drag it down and across to fill out the other prices and hosts. Changing the file size in column A will update the formulae and thus the value and the graph.
From what I understand the price is calculated as follows
price =
(price per view) * (num of views) +
(price per transfer) * (num of views) * (file size) +
(price per storage) * (num of files) * (file size)
So, just add the appropriate relations in excel for the above price model based on the values you want to track.
Related
I'm trying to evaluate various tiered pricing structures (for say, electricity plans) using Excel (more-or-less) to see what costing/plan is 'optimal', given some existing usage data I have.
Consider an example 'Table of Usage & Rates' (with fictitious but easily manipulated values):-
For a daily usage value of 120, we'd have 100 (in the 1st tier) and 20 (in the 2nd tier). The amount used within a tier gets charged at a certain rate (the 'factor')... and each 'tier charge' is addded together to form a total charge for the day.
So, we can calculate:-
100 x 8 = 800 ...a part of the total
20 x 4 = 80 ...another part of the total
...and that's all, giving a total of 880.
...but how to do that in a single formula within a cell?
I've done some pretty decent explorations for a few hours today, as I can't nut out how to deal with this... and most suggestions talk about multiple =IF formulas (cumbersome and unscalable - I shouldn't need to recode cell contents if I split/add another tier)... and suggestions with =VLOOKUP just don't 'click' with me ( = I don't understand them).
I'm actually using 'PlanMaker', a component of Softmaker's 'Office 2021' product to create/maintain this spreadsheet.. and there is no VBA-like plugin available.
I'd appreciate a method of attack, if anyone can suggest something, please...
So:
=product(10,8)+product(20,4)
or if we assume Factor starts in B9 then =product(A9,B9)+product(A10,B10+product(A11,B11)
then take the sum of those results etc assuming A9 is the amount used.
You can also use:
=sumproduct(A9:A11,B9:B11)
for the same but only needs one cell. And the advantage of a lot less typing.
You can include a 3rd array in sumproduct (or as many as needed) such as a binary value to include in the calculation or not.
After looking at a few similarish questions I figured I needed something more specific so asking here. I will start by explaining the situation:
The Setup
I have a Store which sells Cakes, Cookies and Wine. I have the weekly sales data of each product sorta like this:
Product ID
Product Name
Quantity
Value
Week Ending
1
Ginderbread
2
£4
13/01/22
2
Chocolate chip
5
£25
13/01/22
3
Red Wine Bottle
1
£10
13/01/22
4
Sponge Cake
3
£9
13/01/22
Currently every week's data is stored within the same table, with me using a Week filter to show only the week i'm interested in.
Using this Data I created PivotTables that shows the sales of each category, with the ability to drill down to show the specific products. Table looks something like this:
Category
Quantity
Value
Cakes
2
£4
Cookies
7
£29
Wine
1
£10
The issue
I now want to stick in a new calculated column that shows the Value as a %. E.g The total value for the previous table was £43, so Cookies is about 67%. If I drill down, it would show the Chocolate Chip record as 80% and Gingerbread as 20%
I imagine doing this would be easier if each individual week's data was on a different table, but I got a lot of weeks and I also want to do tables showing the sales for over a period of time. Plus I don't know of a way to merge the "value" and "quantity" columns, etc instead of having 1 for each week being shown.
any advice would be appreciated
Create an extra column in the source table (prior to filtering) entitled "perc" calculated as the corresponding value for each row divdied by the total value across all rows (se pic. / eqn. for first row below) --
=E2/$E$6
No calculated fields required - just include perc as the mesaure of interest in your pivot table, with value setting as 'sum':
The reason why this worked is because of the common denominator - which allows one to sum ratios on a 1:1 basis.
Devising a calculated field using the standard 'fields, items & sets' functionality for ordinary pivot tables would not be feasible / possible as far as I am aware. You would need to move into the realm of power pivots and data models - which is not too complicated (readily accesible directly from the field list per below) - however, I see this as unnecessary complication for the task at hand.
Side notes:
Using table names in your functions is sometimes more convenient when entering, albeit may appear tricky at first when reviewing - first eqn above becomes:
=[#Value]/Table1[[#Totals],[Value]]
I have a Google Sheet (Excel formulas apply) containing 2000 transactions that are structured like below:
Link to Google Sheet with example calcs here.
I need to calculate the Profit (ie. FIFO Capital Gains) for every sell order and place this amount in the 5th column (as pictured). This can be achieved with either traditional formulas or with a Google App Script. Preferably in Google Sheets.
I'm finding it difficult via formulas to match the sell order with the buy as you proceed down the table as some sell orders are split across multiple buy lines. If anyone could help with a formula or solution to tackle this problem it would be much appreciated. This is an updated question to the original here.
PRELIMINARY CONTEXT
Screenshot below refers:
Google sheets here
IMPORTANT UPDATE: re: 2000+ rows, see link in my last comment (for OneDrive template, s.t. expiry, and bottom of this proposal for screenshot of error "too large to import")
fyi: (Office 365 - Excel - fns. such as 'filter' etc., so #Name! will be ubiquitous upon opening this link; however, sharing this should serve as a convenient means to replicate above screenshot in the correct version of Excel)
REQUIREMENTS
Office 365
Adequate space to the right or ability to utilise extra sheet for calcs as req.
APPROACH
High-level | Take-aways
• Relies on 2 additional tables: Qty 'depletion' table (here - G:P) and corresp. Profit Vectors (here - R:Z)
• Compressed representations (2x2 tables, per Summary Tables, here: rows 19:32) could be explored to simplify matters (albeit these are still Work in Progress ['WiP'])
• VB could be attractive alternative too
Low-level | Procedural
Single-cell function could not be found without exceptional complication (however, suspect it could be possible e.g. using FilterXML?)
Qty label transposes filtered negative quantities (grey shaded, G3: J3)
These values are depleted in turn (from left to right, i.e. dependency on having data sorted in ascending order by date (in this depiction, data first sorted by 'fruit' as these are assumed to be independent in the context of the profit calc.)
For example, -5 quantity (G3) offset by +10 (B3) to yield +5 which, in turn contributes towards the -35 qty (H3) to yield -30. No further contribution can be made (left to right); next row (5): +20 avail (given), no offset against -5 (G3, already 'reimbursed', so 20 offset against -30 (H4) to yield -10, and so forth.
Worksheet set up to accommodate longer list of fruit / profits
Result table of residual 'quantities' (~ G:J) applied to price differential to yield 'profit vectors' (R:U) which are summed against corresponding negative quantities to produce Profit score (yellow shaded cells)
FUNCTIONS
Salient functions (all of which should be available within Google Sheet, but for completeness):
1) Profit calc. (E4, drag down):
=IF(B4<0,SUM(INDEX($R$4:$AA$13,0,MATCH(A4&C4,$R$2:$AA$2&$R$3:$AA$3,0))),"")
This can be dragged down / to right as far as desired (in this case, goes to: Z13)
2) Qty table - contents (G4)
=IF($A4=G$2,IF(G$3<>"",IF(G$2=E$1,IF($B4<0,IF(G3<0,G3,0), IF(E4<0,0,E4)+IF(G3<0,G3,0)), IF(G$3<>"", IF($B4<0,IF(G3<0,G3,0),$B4 + IF(G3<0,G3,0))))),G3)
3) Qty table - headers (G2, G3 resp.)
=MID(TRANSPOSE(FILTER(A4:A13&B4:B13,B4:B13<0)),1,SEARCH("-",TRANSPOSE(FILTER(A4:A13&B4:B13,B4:B13<0)))-1)
=-1*MID(TRANSPOSE(FILTER(A4:A13&B4:B13,B4:B13<0)),SEARCH("-",TRANSPOSE(FILTER(A4:A13&B4:B13,B4:B13<0)))+1,LEN(TRANSPOSE(FILTER(A4:A13&B4:B13,B4:B13<0))))
Drag to right as far as desired / able to (this case have been dragged to col. P)
4) Profit table - contents (R4, drag down/right)
=IF(R$2<>"",IF(G3>0,0,IF(G4>0,ABS(G3),G4-G3))*(R$3-$C4),"")
5) Profit table - headers (R2, R3 resp.):
=MID(TRANSPOSE(FILTER(A4:A13&"-"&$C$4:$C$13,B4:B13<0)),1,SEARCH("-",TRANSPOSE(FILTER(A4:A13&"-"&$C$4:$C$13,B4:B13<0)))-1)
=1*MID(TRANSPOSE(FILTER(A4:A13&"-"&$C$4:$C$13,B4:B13<0)),SEARCH("-",TRANSPOSE(FILTER(A4:A13&"-"&$C$4:$C$13,B4:B13<0)))+1,LEN(TRANSPOSE(FILTER(A4:A13&"-"&$C$4:$C$13,B4:B13<0))))
MISC
Alternate solutions derived & explored include triangular frameworks
(rows 17-32).
These tabulate the interaction between values assoc.
with positive and negative quantities positive/negative quantities
(and corres. dates)
Should be noted these are otherwise unnecessary (in terms of functions, previous 'section'
Continuing in the same vein as before....
6a) 1st summary table (Qty): row and col headers (A22 - drag down, C19 - drag right resp.):
=FILTER(D4:D13,1*IF($A$21="*",1,(A4:A13=$A$21))*(B4:B13<0))
=TRANSPOSE(FILTER(D4:D13,1*IF($A$21="*",1,IFERROR((A4:A13=$A$21),1))*(B4:B13>0)))
6b) 1st summary table (Qty): running total (c19, drag down / right as req., in this case: to P19)
=SUM($C21:C21,$B22#)
6c) 1st summary table (Qty): content (c22, drag down or tonight as req.)
=IF(OR(C$20="",$A22=""),"",IF($A22>C$20,MAX(0,C21+MIN(0,SUM($B22:B22))),C21))
7) 2nd summary table (Profits): C29, not draggable
=MIN(C$21,C$21+$B22)*($B29-C$28)
Note; other features of 2nd summary table (row / col headers) follow from 1st. Also, placing '*' in the fruit selection cell (A21) returns all (this is still WiP as mentioned previously).
SCREENSHOTS FOR LARGER UPLOAD:
Can I define different aggregation methods for subtotals in different dimension in an Excel pivot table?
The following example shows a result I'm trying to obtain. The metric to aggregate is, let's say, lines of code of a software project. The 2 dimensions in question are Date and Organization. In source data, Organization is broken down into 2 columns, Department and Project, while Date is a single column and Excel makes up the Months/Years summaries automatically when making the ODBC data connection.
A metric such as this one should be aggregated differently along the different dimensions. For the Organization dimension, the subtotal for all projects of the department is the SUM, but in the date dimension, the subtotal for all months of the year is the MAX of any given month (or perhaps AVG, or last etc. but certainly not SUM).
I've tried to define the different aggregation methods in Excel in the field settings, but it always selects one or the other method for both dimensions. Is there a way to do it, preferably using standard Pivot Table mechanisms or at worst a UDF in Excel?
What I would do to tackle this problem is to add both aggregation functions: sum and max , then hide ( or shrink a lot ) those columns you do not want to display.
in the above example I shrink columns B,D,F and I because of they has values that are out of scope for your requirements.
The "Total Max of Loc" displays a value consistent with the function expressed throughout the entire column: that is "the maximum number of lines of code reached by each project in each department; this could lead to misunderstandings when we observe the values of the subtotals and grand total; i.e: The "Grand Total - Total Max of Loc" is not the "Total Max of Sum of Loc": in the example, it shows 18 which represents the absolute maximum value of Loc in a Project in each Department; In the same way the Total Max of Loc for Department 2 is 18 and form Department 1 is 12
When requested a different behavior as expressed in comment to this answer, I think we are entering into the strong customizations space and some solution could be found by writing custom macro and by leveraging the getpivotdata function or, if it can be acceptable for your case, simply by the addition of a new column with the max()formula and possibly hiding the column "Total Max of Loc"
Is there a way to let a pivot table calculate the difference between 2 columns automatically when the values are shown as a % of the parent column total?
Now I need to to manually but the table is dynamic and number of competitors may vary. Function seems so easy but can't find it after googling etc...
See example picture below of what I want to achieve.
(Column F automated by the pivot table is the goal)
If trying to solve this with PivotTables, you've got a couple of options:
Use a 'Traditional' PivotTable that's based on a range. This will give you percentage differences, but you can't get percentage point differences like you're asking for without using external formulas.
Use a 'OLAP' PivotTable that's based on data you've added to the Excel Data Model. This will give you both percentage differences and percentage point differences, without having to resort to using external formulas.
In both cases, I recommend that you unpivot your data first, so that it is in what's known as a Flat File. Currently you're using a cross-tabulated data source (i.e. your source has columns called Year 1, Year 2), and the type of percentage comparisons across years you want to do doesn't work if your data is a crosstab. Basically, PivotTables aren't meant to consume cross-tabulated data.
Instead, you really want your data laid out so that you have a column called Amount and a column called Year, and then you can use the Show Values As options available from the right-click menu to show as percentage differences across years. To transform your data into a flat file, see my answers at convert cross table to list to make pivot table
That said, you can still use the GETPIVOTDATA function on your existing (unpivoted) data layout in a way that is somewhat more robust to changes in your PivotTable structure than just subtracting one reference from the other:
But again, I recommend transforming your data into a Flat File. Then you can additionally do the following:
Using a 'Traditional' PivotTable:
You can kinda solve your problem entirely within a self contained 'Traditional' PivotTable if you drag the Amount column to the Values area, put the Year column in the Columns area, put your Competitors in the Rows area, and choose one of the percentage Show Values As options you'll see when you right-click a cell in the Values area.
I say kinda, because without using external formulas (or without calculating the percentages back in your source data), you can only get it to show percent increases (see far right column), not percentage point increase like you want (see far left column). That said, I think percent increase is less confusing. But I guess it depends on what you want to show. If you want to show say change in market share from one year to the next, then percentage points make sense.
Of course, you could always use the GETPIVOTDATA function to do the additional math for you like we did earlier, like I've done on that left hand side.
Using an OLAP PivotTable based on the DataModel
Calculating percentage point increases likely requires using PivotTables built using the Data Model. See my answer at https://stackoverflow.com/a/49973465/2507160 that explains a little about the Data Model (although it doesn't answer this specific question).
Here's the result:
Here's the measures I used to do this:
Total Year 1:
=CALCULATE(SUM(Table2[Value]),ALLSELECTED(Table2[Competitor]),Table2[Year] = "Year 1")
Total Year 2:
=CALCULATE(SUM(Table2[Value]),ALLSELECTED(Table2[Competitor]),Table2[Year] = "Year 2")
% Year 1:
=CALCULATE(SUM(Table2[Value]),Table2[Year] = "Year 1")/[Total Year 1]
% Year 2:
=CALCULATE(SUM(Table2[Value]),Table2[Year] = "Year 2")/[Total Year 2]
p.p. Diff:
= [% Year 2] -[% Year 1]
You can add Calculated Fields to Pivot Tables, of varying levels of complexity. Finding the difference between two fields is about as simple as it gets.
The example below is borrowed from contextures.com, where there are many more examples more further information.
To add a calculated field:
Select a cell in the pivot table, and on the Excel Ribbon, under the PivotTable Tools tab, click the Options tab (Analyze tab in
Excel 2013).
In the Calculations group, click Fields, Items, & Sets, and then click Calculated Field.
Type a name for the calculated field, for example, RepBonus.
In the Formula box, type =Total * 3%
Click Add to save the calculated field, and click Close.
The RepBonus field appears in the Values area of the pivot table, and in the field list in the PivotTable Field List.
(Source)
EDIT:
#jeffreyweir - I'm not gonna lie, I don't know off the top of my head how to make this work (and don't have time to experiment) but by the looks of these options, isn't a calculated field with a "straight subtraction" of existing fields (ie., 3$-2%=1%) very possible with Difference from? (as opposed to % Difference from which is also an option but for a different result).
In fact, automatic year-over-year difference reporting should be readily possible with the <previous> and <next> comparison operators...?
(Click to Embiggen)
Also, did you see the link where I got the example? Kind of a hoakey site but it has some more complex pivot table instructions.