使用 excel 公式或幂查询将来自主 table 的小时数分配给参考 table 中的所有匹配值

Distributing the hours from master table to all the matching values in reference table using excel formula or power queries

我的主人table包含以下数据

RESOURCE NAME SKILL GROUP PROJECT COST PER HOUR CAPACITY
Resource 1 Automation Testing Project 1 12.0 800.0
Resource 2 DB Testing Project 1 11.0 900.0
Resource 3 DB Testing Project 1 12.0 800.0
Resource 4 Report Testing Project 2 12.0 200.0
Resource 5 CICD and Devops Project 3 11.0 800.0
Resource 6 Performance Testing Project 1 12.0 900.0
Resource 7 Automation Testing Project 2 10.0 250.0
Resource 8 Cloud Testing Project 3 12.0 900.0
Resource 9 Report Testing Project 1 11.0 800.0
Resource 10 Cloud Testing Project 1 11.0 900.0
Resource 11 Report Testing Project 3 12.0 800.0

我的参考资料 table 有这些条目

RESOURCE NAME SKILL GROUP PROJECT DEMAND Capacity
Resource 1 Automation Testing Project 2 900.0
Resource 2 DB Testing Project 1 300.0
Resource 3 DB Testing Project 1 400.0
Resource 1 Report Testing Project 1 200.0
Resource 4 CICD and Devops Project 3 300.0
Resource 5 Performance Testing Project 2 900.0
Resource 6 Automation Testing Project 1 200.0
Resource 2 Cloud Testing Project 2 900.0
Resource 7 Report Testing Project 1 400.0
Resource 8 Cloud Testing Project 3 800.0
Resource 9 Report Testing Project 2 900.0
Resource 10 Pipeline Testing Project 1 600.0
Resource 11 Cloud Testing Project 3 700.0
Resource 10 Performance Testing Project 2 900.0
Resource 11 Automation Testing Project 1 250.0

我在这里试图实现的是将我在 master table 中给出的容量小时数分配给参考文献 table 中的所有匹配记录。

例如: 在 master table 中,资源 10 的总容量为 900 小时,他已分配给参考 table 中的 2 个不同项目,因此他在参考 table 中的容量列将更新,总容量应该分配给每人 450 个,将来如果他被分配了更多项目,那么他的总容量将分配给与资源 10 匹配的所有条目。其他匹配资源也一样。

在 Excel 365:

=XLOOKUP([@[Resource Name]],MasterTable[Resource Name],MasterTable[Capacity])/COUNTIF([Resource Name],[@[Resource Name]])

前几个条目。


我不确定这是否真的是您想要的,但这是一个调整最后一个条目以使同一资源的所有条目都精确到小数点后一位的示例

=LET(totcap,XLOOKUP([@[Resource Name]],MasterTable[Resource Name],MasterTable[Capacity]),
count,COUNTIF([Resource Name],[@[Resource Name]]),
roundcap,ROUND(totcap/count,1),
IF(ROW()<MAX(IF([@[Resource Name]]=[Resource Name],ROW([Resource Name]))),roundcap,totcap-roundcap*(count-1)))

这是没有 let 的公式 - 太可怕了:

=IF(ROW()<MAX(IF([@[Resource Name]]=[Resource Name],ROW([Resource Name]))),ROUND(XLOOKUP([@[Resource Name]],MasterTable[Resource Name],MasterTable[Capacity])/COUNTIF([Resource Name],[@[Resource Name]]),1),XLOOKUP([@[Resource Name]],MasterTable[Resource Name],MasterTable[Capacity])-ROUND(XLOOKUP([@[Resource Name]],MasterTable[Resource Name],MasterTable[Capacity])/COUNTIF([Resource Name],[@[Resource Name]]),1)*(COUNTIF([Resource Name],[@[Resource Name]])-1))

看看这是否适合你,在 powerquery

加载主 table 作为查询。文件 .. 关闭并加载到 ... 仅创建连接。将其命名为 MasterTable

将引用 table(没有容量列)加载到 powerquery 右键单击资源名称,分组依据,[x] 高级 对于第一行,使用操作计数行 对于第二行,使用操作所有行

使用创建的新列顶部的箭头展开数据

MasterTable合并到这个表中,左外连接,使用资源名称列匹配

使用创建的新列顶部的箭头展开容量列

添加列...自定义列.. 将容量除以计数。删除多余的列

let Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"RESOURCE NAME", type text}, {"SKILL GROUP", type text}, {"PROJECT", type text}, {"DEMAND", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"RESOURCE NAME"}, {{"Count", each Table.RowCount(_), type number}, {"Data", each _, type table}}),
#"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"SKILL GROUP", "PROJECT", "DEMAND"}, {"SKILL GROUP", "PROJECT", "DEMAND"}),
#"Merged Queries" = Table.NestedJoin(#"Expanded Data",{"RESOURCE NAME"},MasterTable,{"RESOURCE NAME"},"MasterTable",JoinKind.LeftOuter),
#"Expanded MasterTable" = Table.ExpandTableColumn(#"Merged Queries", "MasterTable", {"CAPACITY"}, {"FULLCAPACITY"}),
#"Added Custom" = Table.AddColumn(#"Expanded MasterTable", "Capacity", each [FULLCAPACITY]/[Count]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count", "FULLCAPACITY"})
in #"Removed Columns"

从稍微不同的输入输出以显示小数