简体   繁体   English

检查Column一列中的每个值以及其他列值

[英]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. ExcelDAX中有什么方法可以检查单个列的所有值是否存在或不在另一列上。

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列中的数字,此信息将随时更新。

  1. Select column B 选择列B
  2. Conditional Formatting -> New Rule -> Use a formula to determine which cells to format 条件格式->新规则->使用公式来确定要格式化的单元格
  3. insert formula as =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并按您的意愿格式化单元格(此处为绿色)
  4. Repeat steps 1 to 2 重复步骤1到2
  5. insert formula as =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并按您的意愿格式化单元格(此处为红色)
  6. Select the column name cell (To remove column heading formatting) 选择列名称单元格(删除列标题格式)
  7. Conditional Formatting -> Clear Rule -> Clear Rules from selected cells 条件格式->清除规则->清除选定单元格中的规则

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查每个列值是否存在于另一个 dataframe 列中,其中另一个列值是列 header - Check if each column values exist in another dataframe column where another column value is the column header 检查一列的值是否在另一个(numpy数组)的值中 - check if values of a column are in values of another (numpy array) 如果另一列中的值彼此相邻,则对 dataframe 中的列值求和 - Sum column values in a dataframe if values in another column are next to each other 对于另一列中的每个唯一值,将值提取到新列中 - extract values into new column for each unique values in another column Python / Pandas-检查列的值是否与另一个列的值相同 - Python/Pandas - check if column's values is the same by another column values 检查一列中的值是否在Python中另一列的间隔值中 - Check if values in one column is in interval values of another column in Python Pandas - 检查列中的设置值是否是另一列中设置值的子集 - Pandas - check if set values in column are a subset of set values in another column 检查列的值是否在 pandas 中另一个 numpy 数组列的值中 - check if values of a column are in values of another numpy array column in pandas 用另一列替换列值 - Replacing a column values with another column 2列的唯一值不在另一列中 - Unique values of 2 column NOT in another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM