How to split money in favor of your partner when the split creates a half penny (OpenOffice) - openoffice.org

I make $98.42. I have a 50% share with a partner, so they get $49.21, and I get $49.21, simple. What if, however, I make $76.33? I want to split the amount in favor of my partner by giving the half penny to them (i.e., from half of $76.33, namely $38.165), that is they get $38.17 and I get $38.16.
Here is what I am working with which causes problems when there is no fractional penny:
=IF(B1="me";ROUNDDOWN(A1/2;2);"") <-- first column
=IF(B1="them";A1;IF(B1="";"";ROUNDUP(A1/2;2))) <-- second column
For each respective ROUNDDOWN/ROUNDUP's I need an IF() to detect if the result of A1/2 splits equally in to two decimals (49.21 and 49.21), not three (38.165 and 38.165)

COLUMN 3 - THE PENNY LESS PERSON
=IF(B1="ME";IF(MOD(((A1/2)*1000);2)=0;A1/2;ROUNDDOWN(A1/2;2));"")
COLUMN 4 - THE PENNY MORE PERSON
=IF(B1="THEM";A1;IF(B1="";"";IF(MOD((A1/2)*1000;2)=0;A1/2;ROUNDUP(A1/2;2)))
Row three (blank) has the formulas above in column 3 and 4 which produces blank spaces as desired.

Related

Filter based on Unique Values that only match certain criteria

This may be beyond my skill level in Google Sheets, and it's certainly straining my brain to think through, but I have two columns out a large spreadsheet (30000 lines or so) that I need to find matches between unique values on one list, and non-unique but specific values ONLY on another list. That is, I would need the following list to return only the values on the left that had a 3 in the right column every time that value appears on the left, not just for a specific instance.
"Unique" Identifier (can repeat)
Value
1
2
2
3
3
2
4
2
5
3
6
2
1
2
2
2
3
2
4
2
5
2
6
2
I have the following formula from another couple answers mocked up, but it doesn't get me all the way there:=UNIQUE(FILTER(A2:A,B2:B>0))
How can I get it to exclude the ones that have, for instance, both a 2 and a 3 in the right column for the same value in the left column?
Edit: To put it in more real terms (I was trying to keep it abstract so I could understand the basics), I have a Catalog ID and a Condition for items, and need to find all Catalog IDs that only have Good copies, not any Very Good copies. This link should show what I want to achieve:
https://docs.google.com/spreadsheets/d/e/2PACX-1vSjenkDS2Mk3t4kTcDoJqSc8AV6ONu4Q17K1HPaIUdJkb7dhdnbAt-CzUxGO3ZoJISNpGajUtFTGz8c/pubhtml?gid=0&single=true
to return only the values on the left that had a 3 in the right column every time
try:
=UNIQUE(FILTER(A:A; B:B=3))
update 1:
=UNIQUE(FILTER(Sheet1!A:A; Sheet1!B:B="Good"))
update 2:
=UNIQUE(FILTER(Sheet1!A:A, Sheet1!B:B="Good",
NOT(COUNTIF(FILTER(Sheet1!A:A, Sheet1!B:B<>"Good"), Sheet1!A:A))))

How to use "if contains"?

I'm trying to make a scheduler for work and I have a dropdown list of the hours that the employees work in one column and I want it to display how many hours it is next to that. I.e.:
Column B (Selected from a drop down menu) Column C
6:00 - 14:30 to display 8 as it is an 8 hour shift
10:00 - 15:00 to display 5 as it is an 5 hour shift
Is there a way to do this?
So for the sake of clarity, I am going to develop this step by step, in several columns. These could be combined into one impenetrable formula, but that will not help you follow. You can do what I suggest here and then hide the columns with the calculation.
Suppose your time is in column A. You can do the following in the first row (mine assumes row 1, if you have headers, probably row 2) and then copy the formulas on down. In column B, I placed, =search("-",A1), which tells where the - sign is. In column C, I find the first time as a string with =left(A1,B1-2), which takes the first characters up to 2 before the dash. In column D I have =mid(A1,B1+2,5) which takes from 2 characters after the dash to the end (if it is only 4 characters long, it copies 4 not 5),and finally in column E we find the desired result, with =HOUR(timevalue(D1)-timevalue(C1)).
That does what you asked. If you wanted to add minutes you could use =MINUTE(timevalue(D1)-timevalue(C1)). Finally if a 22:00 - 6:00 graveyard shift existed, you would need to add logic for it.
You could also simplify the string calculation by in column B using the formula =split(A1,"-") and then putting =HOUR(timevalue(C1)-timevalue(B1))
And so if you really want a single formula, it could be =hour(INDEX((split(A1,"-")),2)-INDEX((split(A1,"-")),1)), which subtracts the first part from the second and converts to hours.
If in the course of time you want to handle the wrap around midnight, =iferror(hour(INDEX((split(A1,"-")),2)-INDEX((split(A1,"-")),1)),24-hour(INDEX((split(A1,"-")),1)-INDEX((split(A1,"-")),2))) should do the trick.
UPDATE: Sheets recognizes the times that resulted from the split as times. So if in B1 you place =split(A1,"-"), D1 can contain =C1-B1 if you are willing to keep the minutes. It even gives the right answer for 22:00 - 2:00.
Make a table with a column for the shifts (this could be the list used for the Validation, if you chose that method) and a column immediately to its right of the respective shift durations. I named that table Larry. Then in C2 (assuming your first dropdown is in B2):
=ArrayFormula(vlookup(B1:B,Larry,2,0))

Repeat row wise a string number of times in corresponding column

Here is a screen shot of some data:
I would like to build a new column that is the the string in column A the total number of times it occurs.
So entry "Too expensive" would be on 26 rows then under that would start "Don't want it" taking up 6 rows, then "too expensive" (different since lower case) would take up another 6 + 5 from row 14.
So just a new column that is each string the number of times it appears. Inverse pivot tabling, if you will.
How would I do that? I tried playing with rept() but that put everything in one cell.
It looks like most likely you first need a helper column to basically unique the values so in column C you would put :
=UNIQUE(A:A)
and for the sake of explanation, if you want to see how it breaks down, in column D you can put
=sum(FILTER(B2:B,exact(C2,A2:A)))
The reason for using exact , is that otherwise it wont be case sensitive.
Once you have your final number for the REPT function you consutruct your repeatable value with a delimiter:
=rept(C2&";",D2)
This helps out split them out properly later into a column, if you rept the value with out the semicolon you will see the same result your describing up top where they are all mashed together.
Currently at this point this is what you would see:
To save some space I nest the sum filter into the rept function so I can remove column D:
=REPT(C2&";",sum(FILTER(B2:B,exact(C2,A2:A))))
I then join all those and split them out one last time using the ; as a delimiter:
=TRANSPOSE(SPLIT(JOIN(";",D2:D4),";"))
Alternatively, see if this works ?
=ArrayFormula(trim(transpose(split(query(rept(A2:A&char(10),B2:B),,50000), char(10)))))

Count selected elements for each line and create an arrayformula that groups by number of counts

We have asked users:
What to do with the money?
[ ] paint the bridge
[ ] rebuild the school
[ ] keep the money
[ ] Other : [____________________]
Here is the spreadsheet with their answers:
A B
1 Name Choices
2 Lilia paint the bridge, rebuild the school, keep the money
3 Paul rebuild the school, paint the bridge, do something else
4 Margerite keep the money, I don't know, do what you want
5 John paint the bridge
...
800
I want a formula that output the number of official choices (excluding other) picked per user.
With the first 4 rows of data, the formula would output this table:
D E
Nbr of choices a user made Frequency (Nbr of users who made these choices)
0 0
1 2
2 1
3 1
Couldn't find a way to get this right from a single formula. For a starter, I wanted to split each line (of B2: B) by "," but couldn't find a way to apply a fn (split) to each line in an formula...
Even with 800 rows of data (B2:B), the resulting table (D2:E5) would always be 4 rows long plus titles (and two column wide)
I could do this in C2, and replicate manually with the "+" corner icon...
=countif(B2;"*rebuild the school*")+countif(B2;"*keep the money*")+countif(B2;"*paint the bridge*")
And then do in E2:
=arrayformula(countif(C2:C;D2:D5))
But I'd like to generate the table of frequencies in one formula, without any manual action (without C column).
So I am looking for a way to "map" the first function to each row, put this in the second fn.
ANSWER by Akshin Jalilov EXPLAINED
This is the answer by Akshin Jalilov, but shorter (and with international notations)
=ARRAYFORMULA(COUNTIF(ARRAYFORMULA(IF(B2:B="";;COUNTIF(ARRAYFORMULA
(IFERROR(IF(FIND("paint the bridge";B2:B);Row(B2:B);0)));"="&row(B2:B))
+COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND(
"rebuild the school";B2:B);Row(B2:B);0)));"="&row(B2:B))
+COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND(
"keep the money";B2:B);Row(B2:B);0)));"="&row(B2:B))));"="&D2:D5))
Step1:
IF(FIND("rebuild the school";B2:B);Row(B2:B);0)
This means, for each row (B2:B) find "rebuild the school". If you find it, return the number of the row, otherwise, return 0.
Step2:
=ARRAYFORMULA(IFERROR(Step1))
Wrap this in an ARRAYFORMULA so that you return the results for each row.
I think IFERROR is there to prevent an error from stopping the process.
Step3:
=ARRAYFORMULA(IF(B2:B="";;COUNTIF(ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge";B2:B);Row(B2:B);0)));"="&row(B2:B))+countif(Step2)+countif(ARRAYFORMULA(IFERROR(IF(FIND("keep the money";B2:B);Row(B2:B);0)));"="&row(B2:B))))
This will count valid votes made by each users. This is equivalent to C2 formula referred in my manual process. But is it now part of a single global formula.
Step4:
Lastly, the rest of the formula counts frequencies of each voting count possibilities.
I know this formula is large but this is the closest I got to what you want.
Now to make it easy, name your responses range "Responses". I assume it is B2:B.
Here is the formula:
=ARRAYFORMULA(Countif(ARRAYFORMULA(IF(Responses="",,COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),2),"="&row(Responses))+COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),3),"="&row(Responses))+COUNTIF(VLOOKUP(row(Responses),({ARRAYFORMULA(Row(Responses)),ARRAYFORMULA(IFERROR(IF(FIND("paint the bridge",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("rebuild the school",Responses),Row(Responses),0))),ARRAYFORMULA(IFERROR(IF(FIND("keep the money",Responses),Row(Responses),0)))}),4),"="&row(Responses)))),"="&D2:D5))
Here is an example if how it works. I am not sure which one exactly you wanted so added both

Small in arrayformula (Google Spreadsheet)

I have 5 columns of numbers that I want to sort per row into another set of columns. I figured I need to use small() (e.g. small(a2:e2,1) for f2; small(a2:e2,2) for g2 and so on). Is there away to iterate this for the next rows; if possible using only native google spreadsheet formulas?
Thanks in advance
I was able to make a temporary work around, but I had to use 3 cheat columns. It looks ok for now but I imagine it will be troublesome for really huge numbers.
Here's a sample sheet for reference: https://docs.google.com/spreadsheets/d/1MQTP2XkRsPRAnPQ5wLhkR8JoNVY6YOExVlOkkX8UeRs/edit#gid=0
The original data are in A3:E
The first cheat column (G3:G) simply creates a column of numbers from 1 to the largest number found in the source data. 1-9 is changed to 01-09 for easier searching. "#" is then added at the end-this will come handy later:
Cheat Column 1 =filter(if(row(A:A)=max(A:E)+1,ʺ#ʺ,text(row(A:A),ʺ00ʺ)),row(A:A)<=max(A:E)+1)
The second cheat column (H3:H) combines each row into a string separated by "-" with a "#" marker:
Cheat Column 2=filter(text(A3:A,ʺ00ʺ)&ʺ-ʺ&text(B3:B,ʺ00ʺ)&ʺ-ʺ&text(C3:C,ʺ00ʺ)&ʺ-ʺ&text(D3:D,ʺ00ʺ)&ʺ-ʺ&text(E3:E,ʺ00ʺ)&ʺ#ʺ,A3:A<>ʺʺ)
The last cheat column (I3:I) sorts each line (from cheat column 2) by finding each number from cheat column from 01 up to the max number, then the "#" char (this ensures that each line will still have the # end marker). "Find" will return the "position" of each number or an error if it's not found. By using "if", we can make "find" return the actual number or "" instead.
=filter(arrayformula(if(iferror(find(transpose(filter(G3:G,G3:G<>ʺʺ)),H3:H),ʺʺ), transpose(filter(G3:G,G3:G<>ʺʺ)),ʺʺ)),A3:A<>ʺʺ)
The formula above creates as many columns as there are numbers from cheat column 1. To prevent this, a "-" is added to each number then "Concatenate" is used to combine everything into one massive string with each set separated by "#". The string is then split using the "#" marker.
Cheat Column 3 =transpose(split(concatenate(filter(arrayformula(if(iferror(find(transpose(filter(G3:G,G3:G<>ʺʺ)),H3:H),ʺʺ),ʺ-ʺ&transpose(filter(G3:G,G3:G<>ʺʺ)),ʺʺ)),A3:A<>ʺʺ)),ʺ#ʺ))
Each number is then separated into each corresponding column by using mid().
Small 1 =filter(mid(I3:I,2,2)*1,A3:A<>ʺʺ)
Small 2 =filter(mid(I3:I,5,2)*1,A3:A<>ʺʺ)
Small 3 =filter(mid(I3:I,8,2)*1,A3:A<>ʺʺ)
Small 4 =filter(mid(I3:I,11,2)*1,A3:A<>ʺʺ)
Small 5 =filter(mid(I3:I,14,2)*1,A3:A<>ʺʺ)
Note that the formula above is only for numbers 1-99. For larger numbers, the Text() formulas should have more zeroes to correspond to the number of digits of the biggest number. The Mid() formulas should also be adjusted accordingly.
I would like to stress that I am very far from being a spreadsheet expert and that this solution is very "unoptimized". It requires several cheat columns; with the first one even having more rows than the original data. If anyone can help me get rid of the cheat columns (or at least the first one) I will be very grateful.
How about using SMALL like you mentioned in your question?
=small($A3:$E3,column()-columns($A3:$G3))
You will need to change the ranges accordingly. The last $G$3 is the cell just before the cell where the formula is placed.
Sample

Resources