[英]Check each values on Column a column with another column values
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. 在Excel或DAX中有什么方法可以检查单个列的所有值是否存在或不在另一列上。
Example - I have a column called Column 1 where i have some values, like 4,5,2,1. 示例-我有一个名为Column 1的列,其中有一些值,例如4,5,2,1。 now i want to check how many of those values exists on Column 2 !
现在我想检查第2列中有多少这些值!
As an Output, i expected it can Go Green
if the value exists else Red
. 作为输出时,我以为它可以走
Green
,如果该值存在其他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. 我已经到了很多地方,但是找到了唯一有用的结果,我可以在其中找到一个sngle值,而不是单个列中的所有值。
Do anyone knows any way of doing this work ! 有谁知道做这项工作的任何方法!
Since you mention Python, this is possible programmatically with the Pandas library: 由于您提到了Python,因此可以通过Pandas库以编程方式实现:
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: 结果:
Create a (optionally hidden) column that will be adjacent to your search column (in my example that will be column C to column B) 创建一个(可能是隐藏的)列,该列将与您的搜索列相邻(在我的示例中为C列至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 这将确定该值是否包含在第一个数据列表中(如果是,则返回true),然后只需使用简单的条件格式即可
Provides the result as expected: 提供预期的结果:
You can do this easily without adding hidden columns as below. 您无需添加隐藏列即可轻松完成此操作,如下所示。 This will updated anytime if you change numbers in column A.
如果您更改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) = TRUE
并按您的意愿格式化单元格(此处为绿色) =OR(B2=$A$2,B2=$A$3,B2=$A$4,B2=$A$5) = FASLE
and format cells as your wish (here in Red) =OR(B2=$A$2,B2=$A$3,B2=$A$4,B2=$A$5) = FASLE
并按您的意愿格式化单元格(此处为红色)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.