如何计算 PowerBI 中两个表的百分比?

How to calculate percentage across two tables in PowerBI?

我有 2 个表,如下面的屏幕截图所示:

表1

表 1 是每个月参加讲座的新生和进修生的总数。

Table2

表2是提交作业的学生的数据

我的目标是计算参加讲座的学生中有多少百分比的新生和进修生提交了作业。我试着做了一些计算,但它没有按照我想要的方式工作。以下是我计算百分比的方法:

表 1 中的新度量:

Total new student attended = SUM(Table1[New])

表 2 中的新度量:

Total student did homework = COUNT(Table2[Type of Student])

表 2 中的新度量:

Number of new student did homework = CALCULATE([Total student did homework],Table2[Type of Student] = "I am a new student.")

表 2 中的新度量:

% New student did homework = [Number of new student did homework] / Table1[Total new student attended]

结果不对。我认为 Table1 的新措施有问题,但我不确定如何更正它,希望得到一些帮助和建议。任何帮助将不胜感激!

您可以使用下面的 Power Query Advance Editor 代码-[=11= 从 Table2 创建一个新的 table ]

let
    Source = Table2,
    #"Grouped Rows" = Table.Group(Source, {"Month Name"}, {
        {"Count_new", each Table.RowCount(Table.SelectRows(_, each ([Type of Student] = "I am a new student."))), Int64.Type}, 
        {"Count_refresher", each Table.RowCount(Table.SelectRows(_, each ([Type of Student] = "I am refresher student."))), Int64.Type}
    })
in
    #"Grouped Rows"

现在您将拥有一个新的 table,其中包含月度新数据和更新数据等数据。您现在可以使用 month 列加入新的 table 和 Table1,并计算所需的计数和百分比。