substitute a value in a cell with its class, Excel - excel

I got two Excel database. One, regarding only cities and their land, has two main columns:
database1
city land
1 1
2 1
3 2
4 2
The other database shows observations and the city where they happened.
database2
- city
observation1 4
observation2 3
observation3 1
observation4 1
I'd like to substitute each cities with the corresponding land, to get something like that:
- city land
observation1 4 2
observation2 3 2
observation3 1 1
observation4 1 1
How do you think I can achieve that?
solved with xlookup (or cerca.x in italian), I'll show you how:
landdatabase2 =XLOOKUP(citydatabase2;citydatabase1;landdatabase1)
wonderful! thanks everyone

Related

Is there a way to find the closest row match based on a different row match?

I'm working with a data in which there are multiple sets of information in the same column. This is making it difficult to pick out the data I need as it always returns the first result. I am trying to find a way to ensure that the column result returned in a search is based on a different column's value. For example:
Name/Date
01/01/2022
02/01/2022
03/01/2022
04/01/2022
05/01/2022
Bob
1
7
2
6
1
Jane
1
7
9
3
1
Jimmy
8
7
5
4
2
Robin
1
2
9
6
2
Batman
4
7
6
6
8
06/01/2022
07/01/2022
08/01/2022
09/01/2022
10/01/2022
Bob
4
1
4
2
12
Jane
6
21
9
3
1
Jimmy
8
2
5
4
2
Robin
8
5
0
6
2
Batman
5
5
6
6
8
If I wanted to yield the number for Jane on 07/01/2022 (which is 21), is there any way of returning this? I've been able to use =MATCH to pull the correct column based on the date search criteria, but I cannot see a viable way of pulling for a particular person when their name appears multiple times in the same column. Attempting a lookup will return the first result for the name hit (so in the case of my Jane example, it would return row 3 instead of 9). I'm looking to be able to enter a name and a date, and it returns the result from that part of the array.
Is such a thing possible, please? If not, is there any workaround that may help to provide me the same result?
Thanks in advance for your assistance!
This is being attempting in Office 365.
Assuming:
ms365 (specifically access to the BETA-channel);
Equal intervals with the same names at the same postions;
Formula in I4:
=LET(X,WRAPCOLS(TOCOL(B1:F12,,1),6),SUM((A1:A6=I3)*FILTER(X,TAKE(X,1)=I2)))
Assuming your data starts in row 1
A1:F12 - data range
B17 - Jane
B18 - 07/01/2022
=LET(data,A1:F12,names,A1:A12,lookupname,B17,lookupdate,B18,INDEX(data,MIN(LET(rowlist,IF(names=lookupname,ROW(names),0),IF(rowlist>MAX(IF(data=lookupdate,ROW(data),0)),rowlist,""))),MAX(IF(data=lookupdate,COLUMN(data),0))))

Average ifs with or in excel

So, I have this problem, I would like to find the average of a column by using the OR function to check criteria from adjusted columns, I tried putting OR into AverageIf function, fail, also tried the "Average(IF(OR(" again not the correct return. Thought it is a simple thing could be done easily but don't know why it doesn't work. So my table is something like this:
ID: Rate Check 1 Check 2 Check 3
1 5 1 1 1
2 3 1 1
3 2 1
4 4
5 5 1 1
6 3
7 4 1
I would like to find the average of the rate column by checking if there are any value in either Check 1; Check 2 or Check 3 columns, so in the above case i will get the average of all but row with the id 4 and 6. Is this possible without using a helper column?
You can use SUMPRODUCT()
=SUMPRODUCT(((C2:C8<>"")+(D2:D8<>"")+(E2:E8<>"")>0)*(B2:B8<>"")*B2:B8)/SUMPRODUCT(--((C2:C8<>"")+(D2:D8<>"")+(E2:E8<>"")>0)*(B2:B8<>""))
If your first ID starts in A2, use this formula (edited to handle empty values in the "Rate" column):
=AVERAGE(IF(MMULT(LEN(C2:E8)*LEN(B2:B8),ROW(INDIRECT("1:"&COLUMNS($C$1:$E$1)))),B2:B8))

Compare multiple data from rows

I'm looking for a way to compare multiple rows with data to each other, trying to find the best possible match. Each number in every column must be an approximately match the other numbers in the same column.
Example:
Customer #1: 1 5 10 9 7 7 8 2 3
Customer #2: 10 5 9 3 5 7 4 3 2
Customer #3: 1 4 10 9 8 7 6 2 2
Customer #4: 9 5 6 7 2 1 10 5 6
In this example customer #1 and #3 is quite similar, and I need to find a way to highlight or sort the rows so I can easily find the best match.
I've tried using conditional formatting to highlight the numbers that are the similar, but that is quite confusing, because the amount of data is quite big.
Any ideas of how I could solve this?
Thanks!
The following formula entered in (say) L1 and pulled down gives the best match with the current row based on the sum of the absolute differences between corresponding cells:-
=MIN(IF(ROW($C$1:$K$4)<>ROW(),(MMULT(ABS($C1:$K1-$C$1:$K$4),TRANSPOSE(COLUMN($C$1:$K$4))^0))))
It is an array formula and must be entered with CtrlShiftEnter.
You can then sort on column L to bring the customers with lowest similarity scores to the top or use conditional formatting to highlight rows with a certain similarity value.
EDIT
If you wanted to penalise large differences in individual columns more heavily than small differences to try and avoid pairs of customers which are fairly similar except for having some columns very different, you could try something like the square of the differences:-
=MIN(IF(ROW($C$1:$K$4)<>ROW(),(MMULT(($C1:$K1-$C$1:$K$4)^2,TRANSPOSE(COLUMN($C$1:$K$4))^0))))
then the scores for your test data would come out as 7,127,7,127.
I'm assuming you want to compare customers 2-4 with customer 1 and that you are comparing only within each column. In this case, you could implement a 'scoring system' using multiple IFs. For example,:
A B C D E
1 Customer 1 1 1 2
2 Customer 2 1 2 2
3 Customer 3 0 1 0
you could use in E2
=if(B2=$B$1,1,0)+if(C2=$C$1,1,0)+if(D2=$D$1,1,0)
This will return a 'score' of 1 when you have a match and a 'score' of 0 when you don't. It then adds up the scores and your highest value will be your best match. Copying down would then give
A B C D E
1 Customer 1 1 1 2
2 Customer 2 1 2 2 2
3 Customer 3 0 1 0 1
so customer 2 is the best match.

EXCEL - Comparing Two Columns - Removing Repeats

If two households share, they create a tie and this tie has a kinship rank that does not change, no matter how often two households share with each other.
KINSHIP RANK EXAMPLE
As you can see, it doesn't matter in which "direction" the tie happened whether it was household 5 who shared to household 3 or vice versa, the kinship rank is still 1
HH1 HH2 RANK
5 3 1
3 5 1
Therefore, I do not need every tie that occurs between two households, but only the first instance that a tie occurred between the two households.
So here is a sample list of many households who shared with each other, sometimes sharing resources with themselves, sharing only once, or sharing multiple times with the same household.
TWO HOUSEHOLD WITH REPEATED TIES
COL.A COL.B
ROW HH1 HH2
1 1 1
2 1 2
3 1 3
4 2 1
5 2 4
6 3 1
7 3 2
8 3 4
9 4 2
This is what I need it to look like:
TWO HOUSEHOLDS WITHOUT REPEATED TIES
COL.A COL.B
ROW HH1 HH2
1 1 1
2 1 2
3 1 3
4 2 4
5 3 2
6 3 4
What I have done
I wrote a simple command for placing the HH1 and HH2 information into the same cell:
=A1&"|"&B1
In the case of the second row, this looks like 1|2 inside cell C2
HH1 and HH2 are combined in column C so how will I be able to compare all of the households in column C to each other? Perhaps a highlighting rule if a repeat happens? Or in another column list if it is a delete or a keep?
Thank you for your assistance everyone.
I suggest a simple COUNTIFS to do the job like this:
=(COUNTIFS(A$1:A1,B2,B$1:B1,A2)+COUNTIFS(A$1:A1,A2,B$1:B1,B2))>0
starting in C2 and then copy down. It will show TRUE for each row which is within the range above it and false if not. Ich checks for both x/y and y/x (the order doesn't matter)
Now simply filter col C to only show rows with TRUE in it. Then simply select and delete it.
This also works with non numerical values like names.
If you still have any questions, just ask ;)
You also can wrap it up to get more informations like this:
=IF((COUNTIFS(A$1:A1,B2,B$1:B1,A2)+COUNTIFS(A$1:A1,A2,B$1:B1,B2)),"",COUNTIFS(A:A,B2,B:B,A2)+COUNTIFS(A:A,A2,B:B,B2))
For C2 and copy down. C1 gets:
=COUNTIFS(A:A,B2,B:B,A2)+COUNTIFS(A:A,A2,B:B,B2)
This will show you only at the first occurrence how many times it is within the whole range.
All done by phone, may contain errors
Use =((A1*B1)/(A1+B1))*((A1*B1)+(A1+B1)) to create unique identifiers. Then use Remove Duplicates in the Data Tools Pane of the Data Tab to remove all rows containing duplicates. Or, alternatively, use something like =IF(IFNA(MATCH(A2,A$1:A1,0),TRUE())=TRUE,"First Share","") dragged and dropped from row 2 to identify First Shares.

rearranging data in excel

I'm not sure how to ask this question without illustrating it, so here goes:
I have results from a test which has tested peoples attitudes (scores 1-5) to different voices on a 16 different scales. The data set looks like this (where P1,P2,P3 are participants, A, B, C are voices)
Aformal Apleasant Acool Bformal etc
P1 2 3 1 4
P2 5 4 2 4
P3 1 2 4 3
However, I want to rearrange my data to look like this:
formal pleasant cool
P1A 3 3 5
P1B 2 1 6
P1C etc
P1D
This would mean a lot more rows (multiple rows per participant), and a lot fewer columns. Is it doable without having to manually reenter all the scores in a new excel file?
Sure, no problem. I just hacked this solution:
L M N O P Q
person# voice# formal pleasant cool
1 1 P1A 2 3 1
1 2 P1B 4 5 2
1 3 P1C 9 9 9
2 1 P2A 5 4 2
2 2 P2B 4 4 1
2 3 P2C 9 9 9
3 1 P3A 1 2 4
3 2 P3B 3 3 2
3 3 P3C 9 9 9
Basically, in columns L and M, I made two columns with index numbers. Voice numbers go from 1 to 3 and repeat every 3 rows because there are nv=3 voices (increase this if you have voices F, G, H...). Person numbers are also repeated for 3 rows each, because there are nv=3 voices.
To make the row headers (P1A, etc.), I used this formula: ="P" & L2 & CHAR(64+M2) at P1A and copied down.
To make the new table of values, I used this formula: =OFFSET(B$2,$L2-1,($M2-1)*3) at P1A-formal, and copied down and across. Note that B$2 corresponds to the cell address for P1-Aformal in the original table of values (your example).
I've used this indexing trick I don't know how many times to quickly rearrange tables of data inherited from other people.
EDIT: Note that the index columns are also made (semi)automatically using a formula. The first nv=3 rows are made manually, and then subsequent rows refer to them. For example, the formula in L5 is =L2+1 and the formula in M5 is =M2. Both are copied down to the end of the table.

Resources