I have a conflict Matrix, and a list of users with different access, I want to check whether the user as a conflicting access or not - sql

Conflict Matrix: C = conflict, A = accessible, X = same
Conflict Matrix is as below image
Using the above table as an example, if I wanted to find the access for A & B I would look down the first column for A, and across the first row for B.
The intersection of these two letters would return C for Conflict.

If your data table is in cells A1:I9 and your key lookup is in cells K1:L3 (i.e K1 contains C, L1 is Conflict) you can use a combination of VLOOKUP, INDEX and MATCH.
MATCH("A",$A$1:$A$9,0) will return the row number that A appears in on column A.
MATCH("B",$A$1:$I$1,0) will return the column number that B appears in on row 1.
INDEX($A$1:$I$9, RowNum, ColumnNum) will return the value at the intersection of RowNum & ColumnNum
VLOOKUP(ReturnedValue,$K$1:$L$3,2,FALSE) will return the looked up value of C, A or X.
Stick the four formula together to get your final result (change "A" & "B" to the access values you're looking for:
=VLOOKUP(INDEX($A$1:$I$9,MATCH("A",$A$1:$A$9,0),MATCH("B",$A$1:$I$1,0)),$K$1:$L$3,2,FALSE)
Further reading:
MATCH
INDEX
VLOOKUP

Related

Excel 2013 conditional formatting using a formula

I have a spreadsheet in Excel 2013 with Location in Column A, Material Number in Column B and types or groups of materials sorted by material number in Column I J & K. Other columns contain data that is irrelevant here.
Column B can contain the same material number in multiple cells.
I'm trying to find a simpler way to format font and color of the items in Column B by comparing if the item is located in Column I J or K, or not at all (no formatting in that case).
I was entering an individual conditional rule to compare Column B with the value in cell I3, another rule for I4, another rule for I5 and so on.
This is getting unwieldy due to the number of items now in I J & K.
There has to be a simpler, more elegant way to do this. Conditional formatting using exact match is not letting me select a range of cells for the match value.
I just need to format the text in Column B to Bold and Blue if the number exists in Column I also, or Bold and Red if it exists in Column J or Bold and Green if it exists in Column K.
Set up a conditional formatting rule that uses a formula. The formula can contain a Countif function that counts how many times the value in cell B in the current row is counted in column I. For example, starting in row 2, select B2 and add a formatting rule with the formula
=COUNTIF($I:$I,$B2)
Take care to use the current row number in the formula and don't use a dollar sign $ in front of the row number. Set three rules, one for column I, one for J and another one for K.
You don't need a new set of rules for each row. Just apply the three rules to all the rows required.

Searching and comparing various values using VBA

I have to create a macro which will:
Get the value from the cell A1 search this value in column C.
If the value in cell A1 exists in column C, the macro needs to be compare the value in cell B1 with values in column D.
If the value in cell A1 exists in column C AND the value in cell B1 exists in column D, then the text "Values found" should appear in cell E1.
The above needs to happen for all non empty rows in column A.
I was trying to use the following formula:
=IF(ISERROR(MATCH(A2,$C$2:$C$138,0)),"Load number not found","Load number found")
But it not working as I want. I have limited access to internet so I can't check all web sites. Would you please help me. Thanks a lot.
To check if A1 is in column C and if B1 is in column D (in the same row A1 was found in column C), then you need to do the following:
=IF(ISERROR(MATCH(A1,$C:$C,0)),"Load number not found",IF(B1=INDEX($D:$D,MATCH(A1,$C:$C,0),1),"Load number found","Load number not found"))
The first IF checks if A1 is in column C, the second IF checks if B1 is in column D (in the same row A1 was found in column C)
It will return "Load number found" only if both conditions are true. Otherwise it will return "Load number not found".
You can write a macro to do the same thing. But the easier way is to lock the cells in column E only and protect the sheet so that users will not accidentally change any of the formulas.
Update:
Since Column C can have duplicates, need to use the following array formula:
=IF(ISERROR(MATCH(1,(A1=$C:$C)*(B1=$D:$D),0)),"Load number not found","Load number found")
When you paste this formula to E1, make sure to press CTRL + Shift + Enter instead of just pressing the Enter key.
If I understand, a conventional solution with formulae is to concatenate your C and D column data and then search that. If you insert a new columnC with:
=D2&E2
copied down to suit you could apply (but say in ColumnF rather than ColumnE) your existing formula with only slight modification:
=IF(ISERROR(MATCH(A1&B1,$C$2:$C$138,0)),"Load number not found","Load number found")
subject to quite what is in which row.

VLOOKUP by Combining 2 Columns to Form a Unique Key

For the following table,
I want to look up the value in col C. Since the values in col A and col B are not unique, VLOOKUP fails. For example, VLOOKUP(1,table,3) returns 5 and never 1.
However, the combinations of cols A & B are unique. For example, 1blah = 5, while 1foo = 1.
How can I use the combination of cols A & B as a unique key to return the corresponding value in col C?
I'm not sure if this should be implemented with worksheet functions or a custom VBA function. I tried using CONCATENATE to generate the unique key, but this did not work because this results in combinations of numbers and strings.
You can use an array formula:
=INDEX($C$1:$C$7,MATCH("1foo",$A$1:$A$7 & $B$1:$B$7,0))
just select in example D1, enter formula in formula bar and press CTRL+SHIFT+ENTER to evaluate it
The way I usually do it is by concatenating the values separated by a pipe character (|). See the formula in the screenshot below.
Then you can vlookup using the concatenated key.
=VLOOKUP("1|foo",$C$1:$D$7,2,FALSE)
You can use VLOOKUP if your lookup value is a concatenation of your two or more key fields (A2&B2). Then, add a first sorted column in your LUT sheet with the array that is the concatenation of the same key fields. Viola.

Google spreadsheet "=QUERY" join() equivalent function?

This question is concerning joining two databases in Google spreadsheet using =QUERY function
I have a table like so in range A1:C3
a d g
b e h
c f i
I have another table
c j m
a k n
b l o
I want the final table to look like this
a d g k n
b e h l o
c f i j m
I can do this by using a vlookup function pretty easily in cell D1 and paste it down and across, but my dataset is huge. I would need a whole page of vlookups and Google Spreadsheet tells I'm at my limit in complexities.
I look at the Google's Query Language reference... there doesn't seem to be an type of "join" functions mentioned. You would think it would be an easy "join on A" type operation.
Can anybody solves this without a vlookup?
Short answer
Google QUERY Language version 0.7 (2016) doesn't include a JOIN (LEFT JOIN) operator but this could be achieved by using an array formula which result could be used as input for the QUERY function or for other uses.
Explanation
Array formulas and the array handling features of Google Sheets make possible to make a JOIN between two simple tables. In order to make easier to read, the proposed formula use named ranges instead of range references.
Named Ranges
table1 : Sheet1!A1:C3
table2 : Sheet2!A1:C3
ID : Sheet1!A1:A3
Formula
=ArrayFormula(
{
table1,
vlookup(ID,table2,COLUMN(Indirect("R1C2:R1C"&COLUMNS(table2),0)),0)
}
)
Remarks:
Using open ended ranges is possible but this could make the spreadsheet slower.
To speed up the recalculation time :
Replace Indirect("R1C2:R1C"&COLUMNS(table2),0) by an array of constants from 2 to number of columns of table2.
Remove the empty rows from the spreadsheet
Example
See this sheet for an example
Note
On 2017 Google improved the official help article in English about QUERY, QUERY function. It still doesn't include yet topics like this but could be helpful to understand how it works.
So, this answers how you do it WITH a Vlookup-function, but in only one cell.
In your example, given that each table of data has the following cell references:
Table1: Sheet1!A1:C3
a d g
b e h
c f i
Table2: Sheet2!A1:C3
c j m
a k n
b l o
This is how the formula should be constructed.
Join-formula
=ArrayFormula(
{
Sheet1!A1:C,
vlookup(Sheet1!A1:A, {Sheet2!A1:A, Sheet2!B1:C}, {2,3}, false)
}
)
The key to get this formula to work, is to understand how to use curly brackets in the Vlookup Range. You basically define the first cell reference of the Range as the column which is to be a match to the Vlookup Search_Key. The rest of the cell references in the Range is in relation to the columns which you would like to join.
The Index is written as {2,3} to return the second and third column of the Range (the Range consists of a total of 3 columns); curly brackets has nothing to do with Arrayformula in the Vlookup Index, but is necessary to return multiple columns from the Vlookup function. The reason to not write {1,2,3} is because you would not like to include the column which is being used for the purpose of joining.
Example where the column in table2 used for joining, is located in a different column (to the right of the data which is to be joined)
This kind of Join-formula can be utilized even if the join-column in the second table is located as the third column of that table.
Let's say that the raw-data in this example would look like this:
Table1 (Sheet1):
a d g
b e h
c f i
Table2 (Sheet2):
j m c
k n a
l o b
If you write the formula like this, you'll still get the desired outcome (as displayed in the table of joined data):
=ArrayFormula(
{
Sheet1!A1:C,
vlookup(Sheet1!A1:A, {Sheet2!C1:C, Sheet2!A1:B}, {2,3}, false)
}
)
The table of joined data:
a d g k n
b e h l o
c f i j m
In the Join-formula, notice that the third column of Table2 is located as the first cell reference in the Vlookup Range!
The reason to why this works, is because when you use curly brackets in the Range (in conjunction with Arrayformula), the Vlookup Search_Key will NOT look for a column as a common denominator within the raw-data, instead it will use the Array within curly brackets as a reference to find a column as a common denominator (by default this is the first column of the Range).
I've written a comprehensive guide about this topic called:
'Mastering Join-formulas in Google Sheets'
You can use ARRAYFORMULA or YOU can just drag this formula:
after an import or QUERY-ing the first table; in the D column:
=QUERY(Sheet2!A1:C3, "Select B,C WHERE A='" & A1 & "'", 0)
I solved this by using Javascript LINQ (language integrated query).
It lets you specify Javascript with complex join conditions. You can also perform other SQL queries such as Grouping, Projecting, Sorting and Filtering your sheets as if they were database tables. Look at the links below.
Note that in the LINQ query language I replaced all spaces in column names with underscores to make them valid JS identifiers.
https://docs.google.com/spreadsheets/d/1DHtQlQUlo-X_YVfo-Wo-b7315sSk2pxL5ci4Y9lxvZo/edit?usp=sharing
https://script.google.com/d/1R5L2ReHJrBRwyoSoVOFLzEQZiGtxidPfPkAeVownt7SWX6TpacY7gA7j/edit?usp=sharing
If you can map each "index" (a, b, c) to a specific row or column, then you could use the INDEX function.
In this case, you could probably map 'a' to column A (or row 1), 'b' to column B (or row 2), and so on.
Also, Merge Tables seem to address this exact use case.
With the 'other' table in A5:C7, please try:
=query({A1:C3,query(sort(A5:C7,1,TRUE),"Select Col2,Col3")})

Comparing rows to identify matches and mismatches

I have a sheet with 10000+ rows, but the data came from 2 sources, so duplicates exist for the same combination of unique keys. So let's say that columns A and B are the unique identifier. Columns C to K have data about the item specified by the unique key. I need to check if there is a second occurrence of the unique key combination and if so, are the data in columns C to K in the second occurrence the same as in the first occurrence. If they are the same, then copy the row to sheet 2.
if a1 = a2 and b1 = b2 then check if c1:k1 equals c2:k2 -> copy to sheet 2
I need to create separate lists of matches and mismatches.
Have you tried using vlookup? When you do this in both directions, you know what the differences are between the two lists. When doing this, make sure that things like spaces are exactly the same. Try using trim on both lists first to remove extra spaces.