Google Sheets - Running Total with reset [duplicate] - google-sheets

This question already has answers here:
ArrayFormula of Resetting Running Total in Google Sheets
(3 answers)
Closed 6 months ago.
Ok I have the following data from my brokerage:
Amount
Description
-0.5
EXCHANGE FEE
-0.09
CLEARING FEE
-0.25
COMMISSIONS
20
TRADE PAIRED
-0.5
EXCHANGE FEE
-0.09
CLEARING FEE
-0.25
COMMISSIONS
10
TRADE PAIRED
What I would like to do is having a running total that resets after it encounters "TRADE PAIRED" in the Description column. So it would look like this:
Amount
Description
Running Total
-0.5
EXCHANGE FEE
-0.5
-0.09
CLEARING FEE
-0.59
-0.25
COMMISSIONS
-0.84
20
TRADE PAIRED
19.16
-0.5
EXCHANGE FEE
-0.5
-0.09
CLEARING FEE
-0.59
-0.25
COMMISSIONS
-0.84
10
TRADE PAIRED
9.16
Anyone have an ARRAYFORMULA that would be able to do this? I've been to do a continuous running total but it's not resetting after "TRADE PAIRED"
=ArrayFormula(if((G5:G<>"TRADE PAIRED"),MMULT(IF(ROW(D5:D)>=TRANSPOSE(ROW(D5:D))=TRUE,1,0),if(G5:G<>"TRADE PAIRED",n(D5:D),0)),MMULT(IF(ROW(D5:D)>=TRANSPOSE(ROW(D5:D))=TRUE,1,0),if(G5:G<>"TRADE PAIRED",n(D5:D),0))+D5:D)
This is not a duplicate of existing:
ArrayFormula of Resetting Running Total in Google Sheets
As that one is grouping based off a common value. Mine is resetting based on a specific value. Additionally, the formula provided in the link crashes Google Sheets

try:
=INDEX(IF(A:A="",,MMULT(--TRANSPOSE(IF((TRANSPOSE(ROW(A:A))>=ROW(A:A))*(
{0; ARRAY_CONSTRAIN(COUNTIFS(B:B, "TRADE PAIRED",
ROW(B:B), "<="&ROW(B:B)), ROWS(A:A)-1, 1)}=TRANSPOSE(
{0; ARRAY_CONSTRAIN(COUNTIFS(B:B, "TRADE PAIRED",
ROW(B:B), "<="&ROW(B:B)), ROWS(A:A)-1, 1)})),A:A, 0)), ROW(A:A)^0)))

Related

How to find balance stock cost of SKU based on received date?

Above is an example of data in Google Sheets. The green table is to keep track my purchases and the red table is to show the inventory summary.
I am stuck at creating a formula to calculate the Balance Stock Cost.
The Balance Stock Cost should only sum up the cost of unsold quantity from latest received date.
For example, for SKU A, the stock balance is 31 units. The purchases of SKU A sorted by received date will become like this...
Since the stock balance is 31, the formula should sum up the purchases on 10-Jan (5 units x 6), 7-Jan (25 units x 4) and 5-Jan (1 unit x 5.5) which brings the total to 135.5.
Please help me to come up a formula to calculate the Balance Stock Cost based on above requirements. Thanks.
You can try:
=MAP(A18:A,D18:D,LAMBDA(ax,dx,IF(ax="",,SUM(QUERY(SORT(ARRAYFORMULA(split(flatten(A2:A15&"|"&B2:B15&"|"&D2:D15&"|"&MAP(C2:C15,LAMBDA(cx,TRANSPOSE(SEQUENCE(cx,1,1,0))))),"|",0,0)),1,1,2,0),"Select Col3 Where Col4 is NOT NULL AND Col1='"&ax&"' LIMIT "&dx)))))

Value (currency) not being imported correctly with importxml in Google Sheets (due to a dot when price is higher than 999 euros)

I have a question regarding the importxml function. At this moment I'm fetching the price of some of our travel pages to a Google Sheets list so we can track the price development of our packages (travel product, so prices are chaning all the time).
Now I'm facing the next problem. When I'm importing the price of a package that has a price higher than 999 euros (for example 1060 euros) the value I get in my Google Sheets is 1.06 (due to the use of a dot in between the 1 and the 0 (1.060 euros).
Is there a possiblility to import the full price in Google Sheets? Without the dot seperating the numbers?
Formula I use: =importxml(A2, "/html/body/div[7]/div[1]/section[1]/div[2]/div[1]/div/div[1]/div[1]/div/span[3]/span"))
Result I get:
€1.09
Result I should get:
€1090
Example sheet: https://docs.google.com/spreadsheets/d/1uzpLEhpjpVcZI8QTLx_Pz4EFL0YJMPHJU6WR1CVbZ-w/edit?usp=sharing
try:
=SUBSTITUTE(TO_TEXT(IMPORTXML(A2, "/html/body/div[7]/div[1]/section[1]/div[2]/div[1]/div/div[1]/div[1]/div/span[3]/span"))), ".", )

Using Sumifs, where a range can match multiple criteria

I have 2 sheets in Google Sheets:
All contacts w. week/month/year, where we pull all of our deals for the year
Weekly Marketing analytics, where we match up all of this information on a weekly basis
In the Weekly Marketing analytics, every column from B2 to BB2 is a week number (1-53), and A1 is the current year (2021 with this sheet).
I am currently trying to find and sum, every deal value on a 10 week running average (week 1-10, 2-11 etc.) and in order to do that, I've created this formula:
=SUMIFS('All contacts w. week/month/year'!$D:$D;'All contacts w. week/month/year'!$T:$T;$A$1;'All contacts w. week/month/year'!$Q:$Q;C$2:L$2; 'All contacts w. week/month/year'!$E:$E; "ORGANIC_SEARCH")
'All contacts w. week/month/year'!$D:$D - This is the column with all of the revenue for a given deal.
'All contacts w. week/month/year'!$T:$T;$A$1 - This is the column with the year of the deal.
'All contacts w. week/month/year'!$Q:$Q;B$2:K$2 - This is the column I am having trouble with. This is the column with the week number of the deal, and since I am doing a 10 week running average, I want every deal for the last 10 weeks. So all deals from week 1, 2, 3 etc that matches all of the other criteria.
'All contacts w. week/month/year'!$E:$E; "ORGANIC_SEARCH" - This is the last criteria, defining which marketing channel the deal originated from.
Currently this formula returns 0, despite there being a deal in week 4, and I cant work out why the system is missing it?
In the bigger picture, this is the for I want to end out with:
=IF(SUM(C$116:L$116)>0;SUM(SUM(C$143:L$143)/SUMIFS('All contacts w. week/month/year'!$D:$D;'All contacts w. week/month/year'!$T:$T;$A$1;'All contacts w. week/month/year'!$Q:$Q;C$2:L$2; 'All contacts w. week/month/year'!$E:$E; "ORGANIC_SEARCH")); 0)
Quickly checking if there is any deals counted in those weeks, if yes then sum up the marketing cost for a given channel, divided with the revenue of the deals for those given weeks.
It's hard to say without seeing the actual data, but it looks like the Criteria2 argument is problematic, because C$2:L$2 is really an array of criteria. So depending on your version of Excel, it would return either a spilled array or the first element of the array (basically only using C$2 as a criteria.)
If the week numbers are numeric (1,2,3 etc.) instead of text (Week1, Week2, Week3, etc.) then you ought to be able to break it out into 2 criteria using inequalities. For example, suppose L2 is week 11. That means the expression L2-9 provides your lower bound of 2. So in your SUMIFS function you should sum everything greater than or equal to L2-9 AND less than or equal to L2.
Your formula might look something like this:
=SUMIFS('All contacts w. week/month/year'!$D:$D;'All contacts w. week/month/year'!$T:$T;$A$1;'All contacts w. week/month/year'!$Q:$Q;">=" & L2-9; 'All contacts w. week/month/year'!$Q:$Q; "<=" & L2; 'All contacts w. week/month/year'!$E:$E; "ORGANIC_SEARCH")

How to calculate monthly std deviation of daily returns in google sheets using google finance api

how to calculate monlthy std diviatoin of daily returns in google sheets using google finance api?
I think we need to use QUERY()but I am not sure how to form single data set in QUERY() by calling googlefinance() two times
So far
:
My stock symbols are in Column A in sheet .
I want to calculate monthly volatility as mentioned in
https://www.investopedia.com/articles/investing/102715/computing-historical-volatility-excel.asp
I want have a colum that has monthly history volatility against the symbol in colum A :
=QUERY(QUERY(
{
ARRAY_CONSTRAIN(GOOGLEFINANCE("NSE:"&A2, "close", workday.intl(TODAY(),-5), workday.intl(TODAY(),-1), "daily"), 4, 2),
ARRAY_CONSTRAIN(GOOGLEFINANCE("NSE:"&A2, "close", workday.intl(TODAY(),-6), workday.intl(TODAY(),-2), "daily"), 4, 2)
},
"select Col2",
1), "offset 1",0)
With above query, I am able.to get data range which has last N day price in 1st colum and prev day price in colum 2.
I would like to use and extend this to calculate monthly volatility.
I am not sure how to use this price data range to calculate logarithm and and next calculation.
Thanks
This may be an over-simplification of what you're trying to achieve, but can you use the STDEV function on a range of closing values during a month?
=stdev(query(googlefinance("NSE:"&A2, "close", MonthStartDate, eomonth(MonthStartDate,0), "daily"),"select Col2 offset 1",0))
MonthStartDate would be your cell 'named range' containing your month start. Obviously, days, where the markets are closed, would not bring back a value and the STDEV would reflect this.
If the closing price is too simplistic and you need other attributes, then you could combine them in the query.

Tiered Discount Price calculation Google Sheets formula

I'm trying to figure out how to calculate a pricing subtotal based on tiered discount.
I found various examples online for Excel but was not able to grok it and make it work in Google Sheets.
What I'm trying to do is calculate the subtotal for 2 line items based on the green and yellow discount tables:
This would be a correct calculation for 40 site licenses:
20 * 150 + 10 * 120 + 10 * 90 = 5100
try:
=ARRAYFORMULA(SUM({QUERY(({0; I$6:I$12}-I$6:I$13)*-1,
"limit "&MATCH(VLOOKUP(C6, H$6:H$12, 1, 1), H$6:H$12, 0)-1);
C6-VLOOKUP(C6, I$6:I$12, 1, 1)}*
INDIRECT("J6:J"&MATCH(VLOOKUP(C6, H$6:H$12, 1, 1), H$6:H$12, 0)+ROW(H$6)-1)))
spreadsheet demo
The classic approach to this would be
=SUMPRODUCT((C26>H$6:H$12)*(C26-H$6:H$12+1)*(J$6:J$12-n(J$5:J$11)))
Adapted from

Resources