问题
Okay, so I have a Google Sheet that I need to reduce a number down to a specific set of 4 numbers. Then count how many times those numbers occur.
For example:
The numbers it breaks down to: 1, 2, 3, 4
Disregard their individual values other than for the purpose of being broken down.
Now take the number 17
.
Count+Add 1, 2, 3, 4, 1, 2, 3 = 7 r1
Take number 12
Count+Add 1, 2, 3, 4, 1 = r1
The remainder is rounded DOWN
So, basically, it breaks down Cell A1 into a count of how many sequences it takes to reach the total of the number in A1, rounddown.
回答1:
try:
=ARRAYFORMULA(COUNTA(IFERROR(QUERY(MMULT(TRANSPOSE((
ROW(INDIRECT("A1:A"&A2*COUNTA(SPLIT(B2, ","))))<=TRANSPOSE(
ROW(INDIRECT("A1:A"&A2*COUNTA(SPLIT(B2, ","))))))*TRANSPOSE(
SPLIT(QUERY(B2&IF(ROW(INDIRECT("A1:A"&A2))<>"", ",")
,,9^9), ","))), SIGN(TRANSPOSE(
SPLIT(QUERY(B2&IF(ROW(INDIRECT("A1:A"&A2))<>"", ",")
,,9^9), ",")))), "where Col1 <="&A2, 0))))
回答2:
Seems odd but...
Your sequence adds to 10, so your number tens place and above times 4 is your first element. Then if the ones digit is between 6 and 9 you add 3, 3 to 5 add 2, or 1 to 2 add 1. There is probably a more elegant formula that this...
=(INT(A1/10)*4)+IF(MOD(A1,10)>0,1,0)+IF(MOD(A1,10)>3,1,0)+IF(MOD(A1,10)>5,1,0)
来源:https://stackoverflow.com/questions/60234678/reduce-a-number-down-to-a-static-set-of-numbers