How can I automate my scoring formula to count odd rows as 1 for TRUE and even rows as 1 for FALSE?
Backstory
I'm trying to import a quiz that I found in the back of an ancient, eldritch tome into G Sheets. The order of the questions is fixed - the notes in the margins are very specific that a "dire fate" awaits anyone who "dares disturb these ancient mysteries." So I'm putting the questions in G Sheets in order, but in order to count the scores, I need to have every odd row give +1 if the answer is TRUE and every even row give +1 if the answer is FALSE.
Row Number
Question
Answer
Score
1
Dread Cthulhu is my personal Lord and Slayer
TRUE
1
2
Men are destined to master their own fates
FALSE
1
3
This way is madness
TRUE
0
4
These secrets should have stayed buried
FALSE
0
I know I could brute force this with addition, such as
=COUNTIF(C2,TRUE)+COUNTIF(C4,TRUE)+COUNTIF(C6,TRUE)...
but every minute I spend typing, I feel the tendrils of existential dread gnawing at the foundations of my soul. Plus, that sounds super-boring.
So, is there a way to automate having COUNTIF() (or COUNTIFS()) do this for me?
Things That I Have Tried or Thought About
ROW(), but it doesn't seem to play nice with COUNTIFS(), just gives me a 0.
=COUNTIFS(C2:C666,TRUE,A2:A666,ISEVEN(ROW)
Adding a cheater-column that does this for me with ROW(), but I'm worried that tinkering with the table will unleash untold horrors on our world.
Maybe something with DCOUNT or ARRAYFORMULA? But those seem to me MORE forbidden than the Necronomicon, not less.
Did try this, but it's just giving me the total number of true values:
=ARRAYFORMULA(COUNTIFS(A3:A24,ISEVEN(ROW()),A3:A24,TRUE))
What else y'all got?
=ARRAYFORMULA(ABS(C3:C-ISEVEN(ROW(C3:C))))
UPDATE:
To get the total:
=SUMPRODUCT(ABS(C3:C-ISEVEN(ROW(C3:C))))
Matt's formula looks like the way to go. Try this to get the total:
=arrayformula( sum( islogical(C3:C) * abs(C3:C - iseven(row(C3:C))) ) )
Related
apologies for the very basic question but I've created a home-made expenses tracker on Google Sheet just for fun and to improve my skills but I'm struggling to make this formula work.
In tab 1 I have a calendar that looks like this:
In tab 2 I have all my transactions:
My idea was to use sumifs in tab 1 so that for the earnings I can sum all transactions that were done in December 2022 and define that all amounts need to be greater than 0, similarly, for the expenses, all transactions would be less than 0.
I did try this formula which obviously doesn't work as I don't know how to specify whether transactions need to be greater or less than 0:
=SUMIFS(transactions!$D:$D,transactions!$A:$A,$B3,transactions!$D:$D,transactions!D3>0)
I'd really appreciate your help, thank you!
try:
=SUM(FILTER(transactions!D:D, transactions!A:A=B3, transactions!D:D>0))
or:
=BYROW(B3:B11, LAMBDA(x, SUM(
FILTER(transactions!D:D, transactions!A:A=x, transactions!D:D>0))))
So what i need is quite simple, yet somehow i cant get around to find a solution for it.
Basically what i need is for a column, starting from its 2nd row to look list numbers from 1 to 15 and have that sequence repeated all the way to the bottom of the sheet automatically. i was thinking about using arrayformula but couldnt figure out the formula for it.
essentially something like this but it goes all the way down automatically.
Explanation:
You can repeat (REPT) a sequence of numbers from 1 to 15 by using the Sequence formula.
The maximum number of times you want to repeat this sequence will be determined by the total number of rows in your sheet divided by 15.
Solution:
=transpose(split(REPT(concat(JOIN(",",SEQUENCE(1,15)),","),ROUNDDOWN(ROWS(A1:A)/15)),",",true))
Output:
non-REPT solution:
=INDEX(ARRAY_CONSTRAIN(FLATTEN(
SEQUENCE(ROUNDUP(ROWS(A:A)/15), 15)-(
SEQUENCE(ROUNDUP(ROWS(A:A)/15), 1, 0)*15)), ROWS(A:A)-ROW()+1, 1))
I would like to find the most recent three results (front top to bottom) in a Google Sheet where column L is "Signed" and the result (column T) is not 0 or blank.
I have the below so far which gives me the first result but not filtered by column L and not excluding 0 or blank cells.
=ARRAYFORMULA(IFERROR(INDEX('Print List'!T$2:T,SMALL(IF("Alex"='Print List'!A$2:A,ROW(A$2:A)-1),1))))
(edit: or rather than ignoring 0 or blanks - column F must be "Sold" so could also filter by that.)
I need to display the results for 1st, 2nd and 3rd in separate columns so will replace the 1 at the end of the above with appropriate number.
Hope I have explained myself ok and any help received will be greatly appreciated.
You might try this off to the side somewhere, or on a different tab, where I assume your tab name is Sheet1:
=TRANSPOSE(QUERY('Print List'!A:T,"select T where T>0 and L='Signed' limit 3"))
After a bit more digging I have got it to work! Thanks Matt for pointing me in the right direction.
=IFERROR(INDEX(ARRAY_CONSTRAIN(QUERY('Print List'!A:T,"select T where A='"&$A2&"' and T>0 and L='Signed'",0), 1, 1), 1),"")
EDIT: Improved again using Matt's edited suggestion:
=IFERROR(TRANSPOSE(QUERY('Print List'!A:T,"select T where A='"&$A2&"' and F='Sold' and L='Signed' limit 3","")),"")
Thank you.
I've seen a hundred questions with the same 'title', however I can't figure out the right answer for my problem (or maybe it gets too hard for me).
It's about a Dungeons & Dragons sheet I'm creating for me and my friends.
First a screenshot: http://prntscr.com/khmo43
What I would like is, when I input a number below 'Experience - Cell G2' (like 250), the output in cell F2 would be 1 (since a character is level 1 between 0-299 experience). However, when the experience becomes 300 or higher (between 300-900) the output should be come 2 in Cell F2.
How can I, in this case, automatically have the output in Cell F2 be determined by the value in G2. (So like, IF G2 is between A and B, F2 = C).
I'm extremely sorry if I asked a double question. I've been looking for ages.
Actually not to hard, one I had a chance to think about it. You want to use an index match with a search key as 1.
From the docs,
search_type: 1, the default, causes MATCH to assume that the range is sorted in ascending order and return the largest value less than or equal to search_key.
Because your levels are going to be sorted (I assume) you can put in the min value needed for a character to advance E.g. 0xp is the min value for level 1, 200xp is the min amount needed for level 2, 500xp is the min amount needed for level 3, etc.
=INDEX($E$2:$E$7, MATCH($A$2,$D$2:$D$7, 1))
Good luck with the campaign!
I have set of columns that I am attempting to calculate the combined total of those columns then subtract from that total 8, if the difference after 8 is equal to or less than 0 I want to only show zero in the column I am doing this formula in. For those who might ask, I am using the ARRAYFORUMLA cause I want this calculation to repeat as I add new rows, keeping the totals I am seeking on the same row as the calculation is being done onto. So far I have most of this working. Well up to the IF ELSE THEN type of portion. My attempt is/was
=if(LTE((B3:B)+(C3:C)-8,0),ARRAYFORMULA((B3:B)+(C3:C)), 0)
As long as I'm understanding you correctly, I believe this will work:
=if(lte(sum(B2:C)-8,0),0,sum(B2:C))
It's at the top of the row and sums columns B and C. You can add more columns easily this way by either changing B/C to something else or passing more columns in.
Sum-8 is greater than 0
Sum-8 is less than 0
If what you want to do is to add each row to the total but only if its sum is 8 or greater, then your original formula was nearly OK but the two parts of the IF statement should have been reversed
=sum(ArrayFormula(if(LTE((B3:B)+(C3:C)-8,0),0,(B3:B)+(C3:C))))
You could also take most of the brackets out
=sum(ArrayFormula(if(LTE(B3:B+C3:C-8,0),0,B3:B+C3:C)))
and this would also work
=sum(ArrayFormula(if(LTE(B3:B+C3:C,8),0,B3:B+C3:C)))
Short answer
ARRAYFORMULA that can show 0 if the value is less than or equal to zero. Otherwise show the value of that set of data:
=ArrayFormula(IF(LTE(A1:A3,0),0,A1:A3))
Explanation
The basic IF syntax requires the use of scalar values, to use it with arrays, ARRAYFORMULA is required as an outer function:
ARRAYFORMULA(IF(array_logical_expression,array_if_true,array_if_false))
For the specific case described on the body of the question, the corresponding formula is:
=ARRAYFORMULA(IF(LTE(B3:B+C3:C-8,0),0,B3:B+C3:C))
Reference
Google Docs editors Help
IF
ARRAYFORMULA
Using arrays in Google Sheets