首页 > 解决方案 > 比较两个表并显示缺失的数据 - Power BI

问题描述

我有数百条线路,其中包含我的员工在这一年中学习的不同课程。而且我还有一张表,上面有他们必须参加的必修课……我想找到一种方法来比较这两张表,看看缺少哪些课程。如果有人帮我提供执行“完成栏”的想法,我也将不胜感激(例如:员工 1:参加了 78% 的课程)

为了说明我拥有的数据:

表 1(2021 年培训)

布鲁诺 | 课程 A
布鲁诺 | 课程 B

表 2(2021 年强制性培训)

课程 A
课程 B
课程 C

期望的输出(缺少的课程):

布鲁诺 | 课程 C

非常感谢。

标签: excelpowerbi

解决方案


查看代码中的注释,并探索 Applied Steps 窗口,以了解算法

培训2021
在此处输入图像描述

强制性培训2021
在此处输入图像描述

M代码

let
    Training2021= Table.FromRecords(
        {[Name="Bruno", Course="Course A"],
        [Name="Bruno", Course="Course B"],
        [Name="George",Course="Course A"],
        [Name="George",Course="Course C"],
        [Name="Sandra",Course="Course C"]},
        type table [Name=Text.Type, Course=Text.Type]),
    MandatoryTraining2021= Table.FromRecords(
        {[Course="Course A"],
        [Course="Course B"],
        [Course="Course C"]},
        type table[Course=Text.Type]),

//group training table by Name
    group = Table.Group(Training2021,"Name",
                {"Courses", each [Course]}
            ),

//Missing courses using List.RemoveMatchingItems
    #"Added Custom" = Table.AddColumn(group, "Missed", each 
            Text.Combine(
                List.RemoveMatchingItems(
                    MandatoryTraining2021[Course],[Courses]),"; "), type text),

//Percent Completed
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "% Taken", each 
        List.Count([Courses])/Table.RowCount(MandatoryTraining2021),Percentage.Type),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Courses"})


in
    #"Removed Columns"

结果
在此处输入图像描述


推荐阅读