Reputation: 2422
Is there any way in Excel or in DAX i can check if all the values of a single column exist or don't on another column.
Example - I have a column called Column 1 where i have some values, like 4,5,2,1. now i want to check how many of those values exists on Column 2 !
As an Output, i expected it can Go Green
if the value exists else Red
.
I have looked in a lot of place but the only useful result i have found where i can find for a sngle value, not for all the values in a single column.
Do anyone knows any way of doing this work !
Upvotes: 0
Views: 1594
Reputation: 589
You can do this easily without adding hidden columns as below. This will updated anytime if you change numbers in column A.
=OR(B2=$A$2,B2=$A$3,B2=$A$4,B2=$A$5) = TRUE
and format cell as your wish (here in Green)=OR(B2=$A$2,B2=$A$3,B2=$A$4,B2=$A$5) = FASLE
and format cells as your wish (here in Red)Upvotes: 2
Reputation: 7099
Create a (optionally hidden) column that will be adjacent to your search column (in my example that will be column C to column B)
=IF(ISERROR(VLOOKUP(B1,$A$1:$A$4, 1, 0)), FALSE, TRUE)
This will determine, if the value is contained within the first data-list (returns true if it is) And then just use simple conditional formatting
Provides the result as expected:
Upvotes: 2
Reputation: 164773
Since you mention Python, this is possible programmatically with the Pandas library:
import pandas as pd
# define dataframe, or read in via df = pd.read_excel('file.xlsx')
df = pd.DataFrame({'col1': [4, 5, 2, 1] + [np.nan]*4,
'col2': [6, 8, 3, 4, 1, 6, 3, 4]})
# define highlighting logic
def highlight_cols(x):
res = []
for i in x:
if np.isnan(i):
res.append('')
elif i in set(df['col2']):
res.append('background: green')
else:
res.append('background: red')
return res
# apply highlighting logic to first column only
res = df.style.apply(highlight_cols, subset=pd.IndexSlice[:, ['col1']])
Result:
Upvotes: 3