Formula to give itemized sum - google-sheets

I have the following sheet (link). What formula would yield the itemized sums in B2, C2, and D2?
To calculate the value in B2, the formula should check cells B5:B10 and sum the corresponding values from A5:A10 for non-blank cells. Hence: 30+45+30=105.
I have tried ARRAYFORMULA(IF(B5:B10 != ""), sum(A5:A10)) which results in Formula parse error.

Considering that the numbers in column B are not to used (thats what i figured out from your example).
you can use sumIf:
=SUMIF(B5:B10,">0",A5:A10)
so this will check if the cell in column B is greater than 0, then it will add its corresponding value from column A.
please note that if you put a character in the B column the SUMIF will not consider it because we are using ">0" as criterion, instead use ISBLANK.
hope it helps.

Related

Summing specific values in a joined list

I am having some difficulties summing up some values in Google Sheets. In my spreadsheet, from multiple other tabs, values and bonuses are combined into one cell (Cell B1 in this example). The format of each "unit" of data is Name,5%xxx (Where "Name" is the name of the item, "5%" represents the sum I want to add, mostly always a percentage, and "xxx" separates one unit from the next). As you can see in cell B1, there are two instances where "Parkour" receives a bonus to sum up (from different sources).
Parkour,5%xxxParkour (Subskill: Sense of Balance),10%xxxParkour,2%xxx
Parkour
0.07
Parkour (Subskill: Sense of Balance)
H2H Combat: Parkour
The formula in cell B2 is:
=IFERROR(SUM(ARRAYFORMULA(IFERROR(VALUE(MID(FILTER(SPLIT(TEXTJOIN("",TRUE,filter(B$1,regexmatch(B$1,$A2)=TRUE)),"xxx"),SEARCH($A2,SPLIT(TEXTJOIN("",TRUE,filter(B$1,regexmatch(B$1,$A2)=TRUE)),"xxx"))),len($A2)+2,1000)),""))),"")
(Dragged down through the rest of the list) (Could not figure out how to make the formula "in line" on the question.)
Expected Results:
B2 = .07 (Working)
B3 = .1 (Not working)
B4 = Blank (Working)
The goal of the formula is to look into cell B1, and split everything out by "xxx". Then, filter the array of items with only exact matches with the line item in column A, then split again by the comma and add up those values. It worked for the first line item, but not the second. (Unsure why, but I strongly believe it has something to do with the parenthesis. When I removed the parenthesis from the name in Column A (and adjusted cell B1 to not have parenthesis), it worked. However, given the structure of the data, parenthesis are required, and I need to find a way for it to work with them.)
When I removed the IFERROR wrap around it in cell B3, I get this error note:
Function SUM parameter 1 expects number values. But " is a text and cannot be coerced to a number.
Any help is greatly appreciated.
You may find useful combining SPLIT with QUERY like this. It will group names and sum percentages:
=QUERY(INDEX (IFERROR(SPLIT(FLATTEN(INDEX(SPLIT(B1:B100,"xxx"))),","))),"SELECT Col1,SUM(Col2) where Col1 is not null group by Col1")
PS: invented a couple of extra line
UPDATE
I've thought you had another goal, try this formula. Having the previous chart generated by QUERY, I used VLOOKUP to match first column and return second one:
=INDEX(IFERROR (VLOOKUP(A2:A,QUERY(INDEX (SPLIT(FLATTEN(SPLIT(B1,"xxx")),",")),"SELECT Col1,SUM(Col2) where Col1 is not null group by Col1"),2,0)))

ARRAYFORMULA is only populating the first row

I have financial data that I am trying to summarize in a format that can be used by a line chart.
The example spreadsheet is here.
In my source data on the left, I have an entry per Date, Symbol, Account. I need to transform this data so there is a row per Date and a column for each Symbol. I will SUM Total Value regardless of account.
I found a way to pull a unique Date (see H2), and then transpose unique Symbols into columns (see I1).
I also found a way to use SUMIFS to get the aggregation I want (take a look at cell I2), but I can't figure out how to use ARRAYFORMULA to apply this value to all rows in column I.
I know I can drag my formula from I2 down to I3,I4,I.. etc, but this sheet is part of a larger project so I'd like it to auto-populate as dates are added to H.
From what I've read ARRAYFORMULA should apply the formula to multiple rows. What am I missing?
Thanks
use:
=QUERY(A1:F, "select A,sum(F) where A is not null group by A pivot B", 1)
Use formulas like this
=ARRAYFORMULA(IF(H2:H="",,SUMIFS($F$2:$F, $A$2:$A, $H2, $B$2:$B, I$1)))
Add IF(H2:H="",,
Explanation
if the range is empty "" do nothing ,, else Your formula
Your Example
Cells
Formulas
I2
=ARRAYFORMULA(IF(H2:H="",,SUMIFS($F$2:$F, $A$2:$A, $H2:H, $B$2:$B, I$1)))
J2
=ARRAYFORMULA(IF(H2:H="",,SUMIFS($F$2:$F, $A$2:$A, $H2:H, $B$2:$B, J$1)))
K2
=ARRAYFORMULA(IF(H2:H="",,SUMIFS($F$2:$F, $A$2:$A, $H2:H, $B$2:$B, K$1)))

Summing over values in Google Sheets after applying a formula

I have a column of strings of the form
n|m
where n<m are natural numbers and I want to calculate the sum of this column where each cell has value m-n (m minus n). I can calculate the respective values into a separate cell via:
=INDEX(SPLIT(A1,"|"), 0,2)-INDEX(SPLIT(A1,"|"), 0,1)
and sum over those but I would like to do it in one step just as one formula below the specified column in one cell. Is that possible?
Thanks
Try in B1
=ARRAYFORMULA(SUM(IFERROR(INDEX(SPLIT(A1:A,"|"), 0,2)-INDEX(SPLIT(A1:A,"|"), 0,1))))
if you want to get the sum below the last value, i.e. row#8
=ARRAYFORMULA(SUM(IFERROR(INDEX(SPLIT(A1:A8,"|"), 0,2)-INDEX(SPLIT(A1:A8,"|"), 0,1))))

Lookup multiple values from one cell

Trying to obtain desired output shown in E:G from a data show in A:C. I can write a formula
JOIN(", ", FILTER($B$2:$B,$C$2:$C=E2,$A$2:$A=F2))
If there would be a single value in F2 I could get comma-separated output items from column B. But I need to do that for more than one value in F2 cell and get the output shown in column G. How to write a formula that can generate column G as desired?
Any help is welcome.
If you're happy with formula dragging down each cell, as per your example in cell F2, then G2 could be:
=join(",",unique(filter({$A:$A&"("&$B:$B&")"},$C:$C=$E2)))
There are more complex formula to do the calcs with an arrayformula.
Within the filter, there are {} brackets that are used to build an array of data. The array consists of Col A then ( then Col B then ).
It then works the same way as per your example in cell F2. The filter finds each row of the array where Col C matches the value in Col E. Unique and join get the results the same way.
When you drag down the formula, textjoin might be more helpful in ignoring empty cells than join.
Use this in cell F2:
=textjoin(",",true,filter(A:A,C:C=E2))
this in cell G2:
=textjoin(",",true,unique(filter(if($A:$A<>"",{$A:$A&"("&$B:$B&")"},),$C:$C=$E2)))
Using arrays in Google Sheets
https://support.google.com/docs/answer/6208276/using-arrays-in-google-sheets?hl=en-GB

How to find a value from a range of cells and place at a specific in google sheet

Suppose I have only one value anywhere at the cell range C2:Z2, I want that value at B2. What can I do?
I need this solution for all the rows bellow this also. The value might at C:C column at one row, at H:H column at another, that means it is dispersed at the range but there will be only one value at the range in a row.
Place this formula in B2:
=ARRAYFORMULA(TRIM(TRANSPOSE(QUERY(TRANSPOSE(C2:Z), , COLUMNS(C2:Z)))))
The formula above works for any type of values.
If your values are numbers then a simpler formula could be used (MMULT does row wise sum here):
=MMULT(
ARRAYFORMULA(--(C2:Z)),
SEQUENCE(COLUMNS(C2:Z), 1, 1, 0)
)
You can use FILTER()
=FILTER(C2:Z2, NOT(ISBLANK(C2:Z2)))
Reference:
FILTER()
if there will be only one value in the row then a simple sum function will do the job for you. put this in B2 ..
=sum(C2:Z2)

Resources