SUM contiguous values in column - google-sheets

Is it possible to SUM groups of contiguous values in a column without manually grouping them one by one the way I have in this picture?
sample sheet

=ARRAYFORMULA(SUBSTITUTE(TRANSPOSE(SPLIT(CONCATENATE({"♥"&MMULT(
SPLIT(TRANSPOSE(SPLIT(TEXTJOIN(" ", 1, IF(INDIRECT("A2:A"&MAX(IF(A2:A<>"",
ROW(A2:A), )))="", "♦", A2:A)), "♦")), " ")*1, ROW(INDIRECT("A1:A"&COLUMNS(
SPLIT(TRANSPOSE(SPLIT(TEXTJOIN(" ", 1, IF(INDIRECT("A2:A"&MAX(IF(A2:A<>"",
ROW(A2:A), )))="", "♦", A2:A)), "♦")), " ")*1)))^0),IF(
SPLIT(TRANSPOSE(SPLIT(TEXTJOIN(" ", 1, IF(INDIRECT("A2:A"&MAX(IF(A2:A<>"",
ROW(A2:A), )))="", "♦", A2:A)), "♦")), " ")<>"", "♥♠", )}), "♥")), "♠", ))

Related

Calculating statistical data for data sets by using single values with multiple quantities in Google Sheets

In Google Sheets, I've been working on data sets of varying prices to compare them to actual costs and excluding values outside of the normal ranges. I've had help previously, but I am unable to design more formulas based on the original formulas I've had help with.
In my data sets, I have very large expanding data sets I've typed manually where multiple numbers occur over again. I've notated each value with multiple values as value (x) where as the X represents the quantity or total amount of occurrences within the data set to make it smaller; as I need to type each manually
The formula to calculate the Average is below:
=ARRAYFORMULA(SUM(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(ISNUMBER(A19:AP19), "♦"&A19:AP19&" 1", IF((A19:AP19<>"")*(NOT(ISNUMBER(A19:AP19))), "♦"&REGEXREPLACE(A19:AP19, "[()]", ), ))),,99^99)),,99^99), "♦")), " "),
"select Col1*Col2 label Col1*Col2 ''", 0))/SUM(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(ISNUMBER(A19:AP19), "♦"&A19:AP19&" 1", IF((A19:AP19<>"")*(NOT(ISNUMBER(A19:AP19))), "♦"&REGEXREPLACE(A19:AP19, "[()]", ), ))),,99^99)),,99^99), "♦")), " "),
"select Col2", 0)))
This works extremely well. I've also have a formula that calculates the Min and Max of the data set.
I've attempted to edit the code to give myself for mode (which will not read value (x) values), and IQR (Interquartile Range) with absolutely no success.
I want to be able to find the Standard Deviation, Mean Deviation, and IQR for datasets while using values that are notated using values (x)
Below is a link of a sample of a data set:
https://docs.google.com/spreadsheets/d/15-UY7salQ8fI011twnIKSjEJQWCSVmfV1wErE28gvKw/edit?usp=sharing
base formula (which takes your range B14:B and expands all values which are in format value (x))
=ARRAYFORMULA(TRANSPOSE(SPLIT(QUERY(REPT(
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,1)&"♦",
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,2)),,999^99), "♦")))
AVERAGE (B3)
=ARRAYFORMULA(SUM(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(ISNUMBER(B14:B), "♦"&B14:B&" 1", IF((B14:B<>"")*(NOT(ISNUMBER(B14:B))),
"♦"&REGEXREPLACE(B14:B, "[()]", ), ))),,99^99)),,99^99), "♦")), " "),
"select Col1*Col2 label Col1*Col2 ''", 0))/
SUM(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(ISNUMBER(B14:B), "♦"&B14:B&" 1", IF((B14:B<>"")*(NOT(ISNUMBER(B14:B))),
"♦"&REGEXREPLACE(B14:B, "[()]", ), ))),,99^99)),,99^99), "♦")), " "),
"select Col2", 0)))
RANGE (B4)
=B7-B8
MEDIAN (B5)
=ARRAYFORMULA(MEDIAN(TRANSPOSE(SPLIT(QUERY(REPT(
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,1)&"♦",
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,2)),,999^99), "♦"))))
MODE (B6)
=ARRAYFORMULA(MODE(TRANSPOSE(SPLIT(QUERY(REPT(
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,1)&"♦",
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,2)),,999^99), "♦"))))
MAX (B7)
=ARRAYFORMULA(MAX(QUERY(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(B14:B)
,,99^99)),,99^99), " ")), "where not Col1 contains '-'", 0)))
MIN (B8)
=ARRAYFORMULA(MIN(QUERY(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(B14:B)
,,99^99)),,99^99), " ")), "where not Col1 contains '-'", 0)))
IQR - INTERQUARTILE RANGE (B9)
=ARRAYFORMULA(QUARTILE(TRANSPOSE(SPLIT(QUERY(REPT(
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,1)&"♦",
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,2)),,999^99), "♦")), 3)-
QUARTILE(TRANSPOSE(SPLIT(QUERY(REPT(
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,1)&"♦",
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,2)),,999^99), "♦")), 1))
MEAN DEVIATION (B10)
=ARRAYFORMULA(AVEDEV(TRANSPOSE(SPLIT(QUERY(REPT(
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,1)&"♦",
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,2)),,999^99), "♦"))))
STANDARD DEVIATION (B11)
=ARRAYFORMULA(STDEV(TRANSPOSE(SPLIT(QUERY(REPT(
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,1)&"♦",
INDEX(IF(B14:B="",,SPLIT(IF(ISNUMBER(B14:B), B14:B&" 1", B14:B), " ()"))*1,,2)),,999^99), "♦"))))
Solution
Google Sheets has custom formulas for these statistical varibales. Use these as follow:
Standard Deviation: =STDEV(B14:B113). More info about this here.
Mean (Average) Deviation: =AVEDEV(B14:B113). More info about this here.
IQR: =QUARTILE(B13:B14,3). More info about this here.
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)

Troublesome syntax - ArrayFormula + CONC + Filter

Example
I have this line:
=ARRAYFORMULA(IFERROR(CONCATENATE(SORT(FILTER('Personale-vagter-AFKRYDS'!$B$3:$B$7 & " ",ARRAYFORMULA('Personale-vagter-AFKRYDS'!**G3**:**G7**=TRUE)),1,TRUE)),"error"))
...And it works, but when I try to expand from G3 + G7 to this (C3 + G37):
=ARRAYFORMULA(IFERROR(CONCATENATE(SORT(FILTER('Personale-vagter-AFKRYDS'!$B$3:$B$7 & " ",ARRAYFORMULA('Personale-vagter-AFKRYDS'!**C3**:**G37**=TRUE)),1,TRUE)),"fejl"))
... It doesn't work.
What am I doing wrong?
all ranges in FILTER needs to be the same size. try:
=ARRAYFORMULA(IFERROR(CONCATENATE(SORT(
FILTER('Personale-vagter-AFKRYDS'!B3:B37&" ",
'Personale-vagter-AFKRYDS'!G3:G37=TRUE), 1, 1)),"error"))
UPDATE:
=ARRAYFORMULA(IFNA({
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!C3:C=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0),
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!D3:D=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0),
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!E3:E=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0),
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!F3:F=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0),
VLOOKUP(LEFT(A3:A, 1)*1, SPLIT(TRANSPOSE(TRIM(QUERY(QUERY(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(CC!G3:G=TRUE, "♦"&IF(CC!B3:B="",,VLOOKUP(
ROW(CC!A3:A), IF(CC!A3:A<>"", {ROW(CC!A3:A), CC!A3:A}), 2, 1))&"♥"&"♠"&CC!B3:B, ))
,,9^9)),,9^9), "♦")), "♠"), "select max(Col2) where Col2 !='' group by Col2 pivot Col1")
,,9^9))), "♥"), 2, 0)}))
Please use this in B3 and drag in other cells
ARRAYFORMULA(IFERROR(CONCATENATE(SORT(FILTER(OFFSET('Personale-vagter-AFKRYDS'!$B$3:$B$37,0+(5*(row(A1)-1)),0,5,1) & " ",OFFSET('Personale-vagter-AFKRYDS'!C$3:C$37,0+(5*(row(A1)-1)),0,5,1)=TRUE),1,TRUE)),"fejl"))

Alternating Cycle (T)op/(B)ottom Sequence

Needing either a single array formula or one dragged down the column that will show alternating sequence per a rule set. Ruleset and detailed example are within the attached link here.
https://docs.google.com/spreadsheets/d/1Sdi1jFpBKF2RJeqWNjLybVcwR0G6hvozZZTvcTK1xis/edit?usp=sharing
let cell E79 be:
=IF(E79>55, "T",
IF(E79<45, "B",
LOOKUP(MIN(MAX(INDEX(E2:E78,
MATCH(1,INDEX((E2:E78>55)+(E2:E78<45)*(E2:E78<>""), ), 0)), 45), 55),
{45,55}, {"B", "T"})))
paste this in cell E78 and drag it upwards:
=IF(((E78<55)*(E78>45))*((E79<55)*(E79>45)),,
IF((QUERY({F79:F},"where Col1 is not null limit 1", 0)="T")*(E78<=55)*(E79>=45), "B",
IF((QUERY({F79:F},"where Col1 is not null limit 1", 0)="B")*(E78> 45)*(E79< 55), "T", )))
paste this in G2 cell:
=ARRAYFORMULA(INDEX(SORT({VLOOKUP(ROW(
INDIRECT("F2:F"&MAX(IF(F2:F<>"", ROW(F2:F), )))), IF(INDEX(SORT({
INDIRECT("F2:F"&MAX(IF(F2:F<>"", ROW(F2:F), ))), ROW(
INDIRECT("F2:F"&MAX(IF(F2:F<>"", ROW(F2:F), ))))}, 2, 0),,1)<>"", {ROW(
INDIRECT("F2:F"&MAX(IF(F2:F<>"", ROW(F2:F), )))),INDEX(SORT({
INDIRECT("F2:F"&MAX(IF(F2:F<>"", ROW(F2:F), ))), ROW(
INDIRECT("F2:F"&MAX(IF(F2:F<>"", ROW(F2:F), ))))}, 2, 0),,1)}), 2, 1), ROW(
INDIRECT("F2:F"&MAX(IF(F2:F<>"", ROW(F2:F), ))))}, 2, 0),,1))
and paste this in H2 cell:
=ARRAYFORMULA(
IF(G2:G="T", IFERROR(VLOOKUP(C2:C, {QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY(
SPLIT(TRANSPOSE(SPLIT("♦"&QUERY(IF(G2:G="T", C2:C, )&
IF(F2:F<>"", "♦", ),,999^99), "♦")), " ")*1, "where Col1 is not null", 0)),
"select "&TEXTJOIN(",", 1, IF(LEN(FILTER(F2:F, F2:F="T")),
"max(Col"&ROW(F2:F)-ROW(F2)+1&")", ))&"")), "select Col2"),
FILTER(F2:F, F2:F="T")}, 2, 0)),
IF(G2:G="B", IFERROR(VLOOKUP(D2:D, {QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY(
REGEXREPLACE(TO_TEXT(
SPLIT(TRANSPOSE(SPLIT("♦"&QUERY(IF(G2:G="B", D2:D, )&
IF(F2:F<>"", "♦", ),,999^99), "♦")), " ")*1), "^0$", "999999999")*1,
"where Col1 is not null", 0)), "select "&TEXTJOIN(",", 1,
IF(LEN(FILTER(F2:F, F2:F="B")),
"min(Col"&ROW(F2:F)-ROW(F2)+1&")", ))&"")), "select Col2"),
FILTER(F2:F, F2:F="B")}, 2, 0)), )))
spreadsheet demo
=ARRAYFORMULA(IF(IFERROR(VLOOKUP(INDIRECT("C2:C"&COUNTA(C2:C)),
MIN(FILTER(C2:C, D2:D<45, D2:D<>"")), 1, 0))<>"", "B", ))

How can I JOIN the ARRAY results of this formula with a ","?

I've tried to add JOIN to this formula in every place I can think of, but none seem to be correct.
=ARRAYFORMULA(IFERROR(VLOOKUP(D2:D&E2:E,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦♥"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)))
The results are multiple columns/rows. I want to keep the rows, but JOIN the column values with a ",".
my sheet
like this perhaps:
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(SUBSTITUTE(IFERROR(VLOOKUP(D2:D&E2:E,
TRIM(IFERROR(SPLIT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(
{INDEX(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select Col1,count(Col1) where Col1 is not null group by Col1 pivot Col2", 0),,1), IF(
ISNUMBER(QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2", 0)),
QUERY(IFERROR(SPLIT(SORT(UNIQUE(IF((LEN(tasksAssociations!C2:C&tasksAssociations!D2:D))*(LEN(tasksAssociations!G2:G)),
tasksAssociations!C2:C&tasksAssociations!D2:D&"♦♥"&tasksAssociations!G2:G, )), 1, 1), "♦")),
"select count(Col1) where Col1 is not null group by Col1 pivot Col2 limit 0", 0), )})
,,999^99))), "♥"))), {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}, 0)), " ", "♫")),,999^99))), " ", ", "), "♫", " "))

Turning formula into ArrayFormula Part2

Following on from this question
Turning formula into ArrayFormula
I failed to make it clear that the value cells may also contain multiple values in CSV format. I tried adjusting it to:
=ARRAYFORMULA(IF(LEN(A4:A), IFERROR(VLOOKUP(SPLIT(A4:A,","),
QUERY(TRIM(TRANSPOSE(SPLIT($B$1, ","))),
"select Col1,count(Col1) group by Col1", 0), 2, 0), 0), ))
But no luck. The test sheet is here.
https://docs.google.com/spreadsheets/d/12xATTwuc-e6kXn_OF2Uibg6EgtSGbInI6Q_-vueknXg/edit#gid=0
My original formula is in B4 which works but needs copying down which is what I want to avoid.
=ARRAYFORMULA(IFERROR(VLOOKUP(A4:A, QUERY({QUERY(TRIM(SPLIT(TRANSPOSE(SPLIT(
QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(A4:A), "♠"&A4:A&"♦"&TRIM(IFERROR(
SPLIT(A4:A, ","))), )), , 999^99)), , 999^99), "♠")), "♦")), "select Col1", 0),
ARRAY_CONSTRAIN(IFERROR(VLOOKUP(QUERY(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(
QUERY(TRANSPOSE(IF(LEN(A4:A), "♠"&A4:A&"♦"&TRIM(IFERROR(SPLIT(A4:A, ","))), ))
, , 999^99)), , 999^99), "♠")), "♦")), "select Col2", 0), QUERY(IFERROR(VLOOKUP(
QUERY(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(A4:A),
"♠"&A4:A&"♦"&TRIM(IFERROR(SPLIT(A4:A, ","))), )), , 999^99)), , 999^99), "♠")), "♦")),
"select Col2", 0), QUERY(TRIM(TRANSPOSE(SPLIT(B1, ","))),
"select Col1,count(Col1) group by Col1", 0), {1, 2}, 0)),
"select Col1,sum(Col2) group by Col1", 0), 2, 0), 0), COUNTA(QUERY(TRIM(SPLIT(
TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(IF(LEN(A4:A),
"♠"&A4:A&"♦"&TRIM(IFERROR(SPLIT(A4:A, ","))), )), , 999^99)), , 999^99), "♠")), "♦")),
"select Col1", 0)), 1)}, "select Col1,sum(Col2) group by Col1" ,0), 2, 0)))

Resources