Convert stock transactions into daily holdings in Excel - excel

interested in converting a transaction statement like so:
Date (DD/MM/YY)
Stock
Flow
11/12/20
Apple
200
12/12/20
Microsoft
50
13/12/20
Apple
-100
into something that looks like:
Date (DD/MM/YY)
Apple
Microsoft
10/12/20
0
0
11/12/20
200
0
12/12/20
200
50
13/12/20
100
50
14/12/20
100
50
Appreciate tips on the best way to go about doing so as I'm not quite sure how to approach this, thanks.

Formulas: (using O365) slightly different approach may be needed in other versions
*note that I created a table out of your stock flow data
F1: Date
G1: =TRANSPOSE(UNIQUE(stockFlow[Stock]))
F2: =ROW(INDEX($A:$A,MIN(stockFlow[Date])-1):INDEX($A:$A,MAX(stockFlow[Date])+1))
G2: =SUMIFS(stockFlow[[Flow]:[Flow]],stockFlow[[Stock]:[Stock]],G$1,stockFlow[[Date]:[Date]],">="&$F$2,stockFlow[[Date]:[Date]],"<=" & $F2)
Select G2 and fill down and across as needed.

Use a Pivot table - create a pivot table, Make "Date" a row and "Stock" a column. Then make "Flow:" a value and change the "Value Field Settings" to "show values as" a "Running Total In..." with "Date" as the base field.
Note that the pivot table will not insert dates that aren't in your raw data, but you could insert rows for the missing dates with a zero flow for any stock to get the table you want:

Related

Excel - SUBTOTAL but only where particular criteria is met (SUMIF/AVERAGEIF)

EDIT: The document is set up like a series of dashboards. Some if the data linked to the many graphs is in pivot tables and some just regular tables. Because there are so many graphs, I use some user selection buttons and fields to change what data is shown in these graphs.
Some users open the file in office 2016.
All solutions I found were either limited to 365 or involved creating new data tables or columns which I was trying to avoid as it would mean a fair bit of rework. I instead just used a set of nested IFS and will eventually look at changing these particular pivots to regular tables with index lookups to enable the actual data to be in multiple columns.
I currently use a SUBTOTAL function to either sum, count or average a bunch of cells in a range. I was previously manually filtering the range so I was only totaling the rows I wanted, however the need has arisen to be able to look at several criteria at once.
i.e in the example below, I was previously manually filtering range to only include "Apple" but now I need to be able to total "Apple", "Orange", "Banana" separately, at the same time.
The subtotal fields are used in graphs and I have a cell (F5) that houses a number corresponding to either SUM, COUNT or Average (9, 2 or 1) to use in the subtotal formulas in the "Summary table" which is linked to other functionality within the workbook and I need to still be able to retain that functionality.
Example of how my sheet is setup:
Raw Data
Product Type
Sales QTY
Date
Apple
4
1/9/21
Orange
3
6/9/21
Banana
2
10/9/21
Apple
6
14/9/21
Orange
6
20/9/21
Apple
5
29/9/21
The Criteria I want to match is in Column 1 (Product Type) of the summary table.
Basically, I then want to be able to end up with the ability to display the data either as Totals:
$F$5 = 9
for each line: SUBTOTAL($F$5,SalesQTY)
Summary Table
Product Type
Result (Sales Per Month)
Apple
15
Orange
9
Banana
2
Or as Averages:
$F$5 = 1
for each line: SUBTOTAL($F$5,SalesQTY)
Product Type
Result (Average QTY per Sale)
Apple
5
Orange
4.5
Banana
2
Or as a Count:
$F$5 = 2
for each line: SUBTOTAL($F$5,SalesQTY)
Product Type
Result (# Sales Transactions)
Apple
2
Orange
2
Banana
1
Is there some way I can combine SUMIF and also SUBTOTAL but also be able to retain the ability to flick between average, sum and count?
Here is a formula to create a dynamic summary table in excel 365. If you have any earlier version of excel, the formula would be different and rows would have to be manually added or removed. I'm assuming your table is called Data_Table.
=LET(
Column_Product, Data_Table[Product Type],
Column_QTY, Data_Table[Estimated],
Column_Date, Data_Table[Date]
Column_Key, Column_Product,
Column_Filter1, Column_QTY,
Column_Filter2, Column_Date,
List_Filter1, UNIQUE(Column_Product),
List_Filter2, 1,
Categories, SORT(UNIQUE(Column_Key)),
Array_BoolKey, (TRANSPOSE(Column_Key)=Categories)+0,
Mask1, TRANSPOSE(ISNUMBER(XMATCH(Column_Filter1,List_Filter1))),
Mask2, TRANSPOSE(Column_Filter2>List_Filter2),
Array_BoolMasked, Array_BoolKey*Mask1*Mask2,
Masked_QTY, IFERROR(Array_BoolMasked*TRANSPOSE(Column_QTY),0),
Masked_Date, IFERROR(Array_BoolMasked*TRANSPOSE(Column_Date),0),
Array_Ones, SEQUENCE(COLUMNS(Array_BoolMasked),1,1,0),
Months, DATEDIF(MIN(Column_Date),MAX(Column_Date),"M"),
Body_Count, MMULT(Array_BoolMasked, Array_Ones),
Body_Sum_QTY, MMULT(Masked_FtModeled, Array_Ones),
Body_Average_PerSale, Body_Sum_QTY/Body_Count,
Body_Sum_QTY_PerMo, MMULT(Masked_FtModeled, Array_Ones)/Months,
Total_Count, IFERROR(SUM(Body_Count_Lines),"-"),
Total_QTY_PerMo, IFERROR(SUM(Body_Sum_QTY)/Months,"-"),
Total_Average_PerSale, IFERROR(SUM(Body_Sum_QTY)/Total_Count,"-"),
Array_Seq, {1,2,3,4,5},
Array_Header, CHOOSE(Array_Seq, "Product Type", "Sales Per Month", "Average QTY per Sale", "# Sales Transactions"),
Array_Body, CHOOSE(Array_Seq, Categories, Body_Sum_QTY_PerMo, Body_Average_PerSale, Body_Count),
Array_Total, CHOOSE(Array_Seq, "Total", Total_QTY_PerMo, Total_Average_PerSale, Total_Count),
Range1,Array_Header,
Range2,Array_Body,
Range3,Array_Total,
Rows1,ROWS(Range1), Rows2,ROWS(Range2), Rows3,ROWS(Range3), Cols1,COLUMNS(Range1),
RowIndex, SEQUENCE(Rows1 + Rows2 + Rows3), ColIndex,SEQUENCE(1, Cols1),
RangeTable,IF(
RowIndex<=Rows1,
INDEX(Range1,RowIndex,ColIndex),
IF(RowIndex<=Rows1+Rows2,
INDEX(Range2,RowIndex-Rows1,ColIndex),
INDEX(Range3,RowIndex-Rows1-Rows2,ColIndex)
)),
Return, RangeTable,
Return
)
I wrote this generically so you could add filters for only certain products, or minimum quantity, or a date range, or other criteria. Above, I set up the filter to pass everything.
Solution Used:
To avoid having to rework the many other tables in the sheet that rely on this field and also as some user open this file with older (non-365) versions of excel, I opted for a series of nested IF (CountIF, SumIF, AverageIF) statements instead.

Use a Count field as a row in Excel Pivot table

Not sure if it is possible but I'd like to have a pivot table that summarizes how many occasions properties have been missed, and then shows the number of times properties have been missed that many times.
What I'm looking to end up with is something like the below:
TIMES MISSED PROPERTIES MISSED THAT AMOUNT OF TIMES
1 102
2 76
3 23
4 11
5 2
Information is currently in the following format:
UPRN DATE MISSED
1029292 1/1/2020
1029292 5/6/2020
1010101 1/2/2020
1046353 4/3/2020
3894387 8/2/2020
3894387 7/2/2020
3894387 9/2/2020
So this would give the following table:
TIMES MISSED PROPERTIES MISSED THAT AMOUNT OF TIMES
1 2
2 1
3 1
Is this possible? And if so, how?
Pivot tables in Excel can summarize data not only with SUM function, but also with COUNT and other functions.
Right-click a field in the "Sum values" field chooser and then select Value Field Settings... From there you can choose the function to summarize your data (COUNT in your case).

how to choose and sum data from excel table automatically

I'm setting up an excel data table that i need to make a monthly statistics from it. how can i automatically choose a characteritic from the table and get all its values sumed up ?
This is a garage based data, that includes daily entries and the productivity of every technicien on a daily basis. What i'm asking for is, can i find a way to sort all 5 techniciens in a different table and get their productivity summed up automatically ?
here is the data table and an example for what i am trying to do.
n Date CLIENT Date d'entrée MO Techniciens HT€ Prestation
1 01/03/2019 YAYA 01/03/2019 30 900 FLORENT 30 900 Passage au banc
2 05/03/2019 DAVID 05/03/2019 30 000 LOBA 30 900 Passage au banc
3 07/03/2019 NAME 20/02/2019 60 000 YAPO 60 000 Ctrle injecteurs
4 08/03/2019 MATFORCE 01/03/2019 39 000 LOBA 42 151 Passage au banc
what i want is to have another table with the techniciens name in it and the sum of HT€
technicien heures factures/mois
PRINCE 10 000
MOUSSA
ETIBOIS
Select Data
Insert -> Pivot Table
Set Technicians as Rows and Sum of HT as Values
Source data was slightly altered to better illustrate the answer
Like #Marc in the comment to the question, I would suggest SUMIF(), SUMIFS() or Pivot Tables.
Pivot Tables are the easiest as they can SUM by multiple criteria without a lot of programming. But they only do one thing at a time so SUM and AVERAGE need to be done separately.
SUMIF(range,criteria, sumrange) will return the sum of all of the cells in sumrange that are in the same row where the value in the range meets the criteria for example:
=SUMIF(A1:A999,="Charlie",B1:B999)
Where A1:A999 has the technicians' names, B1:B999 has their billing amounts
SUMIFS() is similar but allows multiple selection criteria.

How to group multiple cells with the same values in Excel

I am trying to group multiple cells in Excel to give me an end value of the total of times those three cells exist, for example, if the Country is "UK", the Method is "Method1" and Weight is "400", instead of that appearing 2 times as it does in the table below, I would like to merge it so it is there only once, but the Amount column has a value of "2" to represent how many times it is in the Sheet. The data I am using has thousands of different and varying values. I am using Microsoft Excel 2016.
Thank you.
Current Sheet:
Country Method Weight Amount
USA Method7 200 x
UK Method1 400 x
UK Method1 400 x
FRANCE Method55 3994 x
Desired Sheet:
Country Method Weight Amount
USA Method7 200 1
UK Method1 400 2
FRANCE Method55 3994 1
This is how my original data looks like:
And I can resume it as you need using Pivot Tables
Make sure you set the Pivot Table Value Property as count when
using the field Amount
Just in case it may help, I'm attaching how I set up this Pivot Table to make the operations you need (please, note my Excel is in Spanish, but position of each field must be the same, and the operation in Values section affecting field Amount must be COUNT)
As there is a direct link between country, method and weight, you can use subtotals for that (menu "Data", chapter "Outline", feature "Subtotals"). You configure it as:
At each change in : "Country"
Use function : "Count"
Add subtotal to:
Country (No)
Method (No)
Weigth (No)
Amount (Yes)
Replace current subtotals (Yes)
Page break between groups (No)
Summary below data (Yes)
Your result will look as follows:
By clicking on the numbers 1, 2 or 3 in the left margin, you'll be able to view/hide subtotals for that country.

Excel: how to NOT sum based on text values?

I am trying to sum values based on another text column.
Let's say my data look like this:
date item amount
4/3/03 book 100
8/3/05 rent 1090
5/6/06 food 5
2/7/09 repair 390
8/3/10 rent 1090
so I want to sum all the spendings (amount) when the "item" section is NOT equal to "rent", but I dont just want a grand sum, I just want a sum that's up to that date.
So the desired output (last column, subtotal) should look something like this:
date item amount subtotal
4/3/03 book 100 100
8/3/05 rent 1090 100
5/6/06 food 5 105
2/7/09 repair 390 495
8/3/10 rent 1090 495
I've tried to sum it up while filtering the rolls to only show anything but rent, but when I clear the filter, all the numbers will sum INCLUDING rent.
I've also tried using SUMIF (I named the top cell in "Amount" column as "first_amount"):
=SUMIF(C2,"rent",first_amount:E2)
But I dont think I'm using it correctly or maybe it just doesn't work. It shows no value whatsoever.
I found this post and read through the function pages, but still am not being able to do what I wanted to do:
Excel summing values based on multiple conditions
BONUS:
What if I want to exclude both "rent" and "food"?
I'm sure there's a very simple solution out there that I am just too dumb to think of. Any hint/help is truly appreciated!
Assuming A1 is the first cell make D1:
=SUMIF($B$2:B2, "<>rent", $C$2:C2)

Resources