如何处理数据透视表 table 中出现的重复条目以及如何填充 excel 仪表板中的电源查询

how to handle repeated entries coming in the pivot table & power query to populate in excel dashboard

我有两个tables capacitydemand

容量table看起来像这样:

RESOURCE NAME SKILL GROUP PROJECT START DATE END DATE COST PER HOUR CAPACITY
Resource 1 Automation Testing Project 1 1-Oct-2021 31-Mar-2022 12.0 800.0
Resource 2 DB Testing Project 1 1-Oct-2021 31-Mar-2022 11.0 900.0
Resource 3 DB Testing Project 1 1-Oct-2021 31-Dec-2021 12.0 800.0
Resource 4 Report Testing Project 2 1-Oct-2021 30-Apr-2022 12.0 900.0
Resource 5 CICD and Devops Project 3 1-Oct-2021 31-Mar-2022 11.0 800.0
Resource 6 Performance Testing Project 1 1-Oct-2021 31-Mar-2022 12.0 900.0
Resource 7 Automation Testing Project 2 1-Nov-2021 31-Mar-2022 10.0 800.0
Resource 8 Cloud Testing Project 3 1-Oct-2021 31-Mar-2022 12.0 900.0
Resource 9 Report Testing Project 1 1-Dec-2021 31-Dec-2021 11.0 800.0
Resource 10 Cloud Testing Project 1 1-Dec-2021 31-Dec-2021 11.0 900.0
Resource 11 Report Testing Project 3 1-Dec-2021 31-Dec-2021 12.0 800.0
Resource 12 Pipeline Testing Project 1 1-Dec-2021 31-Dec-2021 11.0 900.0
Resource 13 Cloud Testing Project 3 1-Dec-2021 31-Dec-2021 12.0 800.0

需求Table是这样的:

RESOURCE NAME SKILL GROUP PROJECT START DATE END DATE DEMAND
Resource 1 Automation Testing Project 2 1-Oct-2021 25-Oct-2021 200.0
Resource 2 DB Testing Project 1 1-Oct-2021 31-Dec-2021 300.0
Resource 3 DB Testing Project 1 1-Oct-2021 31-Dec-2021 400.0
Resource 1 Report Testing Project 1 1-Oct-2021 31-Dec-2021 200.0
Resource 4 CICD and Devops Project 3 1-Oct-2021 31-Mar-2022 300.0
Resource 5 Performance Testing Project 2 1-Oct-2021 25-Oct-2021 400.0
Resource 6 Automation Testing Project 1 1-Oct-2021 31-Dec-2021 200.0
Resource 2 Cloud Testing Project 2 1-Oct-2021 25-Oct-2021 300.0
Resource 7 Report Testing Project 1 1-Oct-2021 31-Dec-2021 400.0
Resource 8 Cloud Testing Project 3 1-Oct-2021 31-Dec-2021 800.0
Resource 9 Report Testing Project 2 1-Oct-2021 31-Dec-2021 800.0
Resource 10 Pipeline Testing Project 1 1-Oct-2021 31-Dec-2021 600.0
Resource 11 Cloud Testing Project 3 1-Oct-2021 31-Dec-2021 700.0
Resource 10 Performance Testing Project 2 1-Oct-2021 31-Dec-2021 250.0
Resource 11 Automation Testing Project 1 1-Oct-2021 31-Dec-2021 250.0

我根据 资源名称 使用 power 查询合并了这两个 table 并尝试生成下面的数据透视表 table.

旋转table截图

我在 table 中的公共字段是 “资源名称”,我试图在 pivot table 中构建的内容将被进一步使用在我的带有切片器的仪表板中。尝试构建这样的仪表板。

仪表板屏幕截图

挑战点:

PowerQuery 合并屏幕截图

最终版Table截图

之后我选择“关闭并加载”选项并选择“上传到数据模型”

这是最终的 Table 样子:

RESOURCE NAME SKILL GROUP PROJECT START DATE END DATE COST PER HOUR CAPACITY DemandTable.RESOURCE NAME DemandTable.SKILL GROUP DemandTable.PROJECT DemandTable.DETAIL DemandTable.START DATE DemandTable.END DATE DemandTable.DEMAND
Resource 1 Automation Testing Project 1 01-10-21 0:00 31-03-22 0:00 12 800 Resource 1 Automation Testing Project 2 01-10-21 0:00 25-10-21 0:00 200
Resource 1 Automation Testing Project 1 01-10-21 0:00 31-03-22 0:00 12 800 Resource 1 Report Testing Project 1 01-10-21 0:00 31-12-21 0:00 200
Resource 2 DB Testing Project 1 01-10-21 0:00 31-03-22 0:00 11 900 Resource 2 DB Testing Project 1 01-10-21 0:00 31-12-21 0:00 300
Resource 2 DB Testing Project 1 01-10-21 0:00 31-03-22 0:00 11 900 Resource 2 Cloud Testing Project 2 01-10-21 0:00 25-10-21 0:00 300
Resource 3 DB Testing Project 1 01-10-21 0:00 31-12-21 0:00 12 800 Resource 3 DB Testing Project 1 01-10-21 0:00 31-12-21 0:00 400
Resource 4 Report Testing Project 2 01-10-21 0:00 30-04-22 0:00 12 200 Resource 4 CICD and Devops Project 3 01-10-21 0:00 31-03-22 0:00 300
Resource 5 CICD and Devops Project 3 01-10-21 0:00 31-03-22 0:00 11 800 Resource 5 Performance Testing Project 2 01-10-21 0:00 25-10-21 0:00 400
Resource 6 Performance Testing Project 1 01-10-21 0:00 31-03-22 0:00 12 900 Resource 6 Automation Testing Project 1 01-10-21 0:00 31-12-21 0:00 200
Resource 7 Automation Testing Project 2 01-11-21 0:00 31-03-22 0:00 10 250 Resource 7 Report Testing Project 1 01-10-21 0:00 31-12-21 0:00 400
Resource 8 Cloud Testing Project 3 01-10-21 0:00 31-03-22 0:00 12 900 Resource 8 Cloud Testing Project 3 01-10-21 0:00 31-12-21 0:00 800
Resource 9 Report Testing Project 1 01-12-21 0:00 31-12-21 0:00 11 800 Resource 9 Report Testing Project 2 01-10-21 0:00 31-12-21 0:00 800
Resource 10 Cloud Testing Project 1 01-12-21 0:00 31-12-21 0:00 11 900 Resource 10 Pipeline Testing Project 1 01-10-21 0:00 31-12-21 0:00 600
Resource 10 Cloud Testing Project 1 01-12-21 0:00 31-12-21 0:00 11 900 Resource 10 Performance Testing Project 2 01-10-21 0:00 31-12-21 0:00 250
Resource 11 Report Testing Project 3 01-12-21 0:00 31-12-21 0:00 12 800 Resource 11 Cloud Testing Project 3 01-10-21 0:00 31-12-21 0:00 700
Resource 11 Report Testing Project 3 01-12-21 0:00 31-12-21 0:00 12 800 Resource 11 Automation Testing Project 1 01-10-21 0:00 31-12-21 0:00 250
Resource 12 Pipeline Testing Project 1 01-12-21 0:00 31-12-21 0:00 11 900
Resource 13 Cloud Testing Project 3 01-12-21 0:00 31-12-21 0:00 12 800

查询:
容量Table

let Source = Excel.CurrentWorkbook(){[Name="CapacityTable"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"RESOURCE NAME", type text}, {"SKILL GROUP", type text}, {"PROJECT", type text}, {"START DATE", type datetime}, {"END DATE", type datetime}, {"SUN", type any}, {"MON", type number}, {"TUE", type number}, {"WED", type number}, {"THU", type number}, {"FRI", type number}, {"SAT", type any}, {"COST PER HOUR", Int64.Type}, {"CAPACITY", Int64.Type}}) in #"Changed Type"

需求Table

let Source = Excel.CurrentWorkbook(){[Name="DemandTable"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"RESOURCE NAME", type text}, {"SKILL GROUP", type text}, {"PROJECT", type text}, {"DETAIL", type any}, {"START DATE", type datetime}, {"END DATE", type datetime}, {"SUN", type any}, {"MON", type number}, {"TUE", type number}, {"WED", type number}, {"THU", type number}, {"FRI", type number}, {"SAT", type any}, {"DEMAND", Int64.Type}}) in #"Changed Type"

决赛Table

let Source = Table.NestedJoin(DemandTable, {"RESOURCE NAME"}, CapacityTable, {"RESOURCE NAME"}, "CapacityTable", JoinKind.LeftOuter), #"Expanded CapacityTable" = Table.ExpandTableColumn(Source, "CapacityTable", {"RESOURCE NAME", "SKILL GROUP", "PROJECT", "COST PER HOUR", "CAPACITY"}, {"CapacityTable.RESOURCE NAME", "CapacityTable.SKILL GROUP", "CapacityTable.PROJECT", "CapacityTable.COST PER HOUR", "CapacityTable.CAPACITY"}) in #"Expanded CapacityTable"

问题是,当我尝试通过数据透视表 table 为我的所有项目和资源的容量与需求构建数据时,我的容量小时数会针对我的需求中存在的每条记录重复 Table。我相信我需要根据项目填充我的数据,但是,不确定需要做什么。

要创建您正在显示的数据透视表 Table,但不复制数据,您可以:

  • 使用JoinKind.FullOuter
  • 加入基于{"RESOURCE NAME","PROJECT"}的两个table
  • 扩展 table 并在 PROJECTRESOURCE NAME 列中为容量或需求中缺少条目的行“填充空值”tables
  • 添加需求*成本列。
  • 清理后,您可以保存并加载到数据透视表 table。

M码

let

//Lodad and Type Capacity Table
    Source1 = Excel.CurrentWorkbook(){[Name="Capacity"]}[Content],
    Capacity = Table.TransformColumnTypes(Source1,{
        {"RESOURCE NAME", type text}, {"SKILL GROUP", type text}, {"PROJECT", type text}, 
        {"START DATE", type date}, {"END DATE", type date}, 
        {"COST PER HOUR", Currency.Type}, {"CAPACITY", Number.Type}}),

//Lodad and Type Demand Table    
    Source2 = Excel.CurrentWorkbook(){[Name="Demand"]}[Content],
    Demand = Table.TransformColumnTypes(Source2,{
        {"RESOURCE NAME", type text}, {"SKILL GROUP", type text}, {"PROJECT", type text}, 
        {"START DATE", type date}, {"END DATE", type date}, {"DEMAND", Number.Type}}),

//Join the two tables
    joined = Table.NestedJoin(Capacity,{"RESOURCE NAME","PROJECT"},Demand,{"RESOURCE NAME","PROJECT"},"Joined",JoinKind.FullOuter),

//Remove unneeded columns and expand the Joined table
    #"Removed Columns" = Table.RemoveColumns(joined,{"SKILL GROUP", "START DATE", "END DATE"}),
    #"Expanded Joined" = Table.ExpandTableColumn(#"Removed Columns", "Joined", 
        {"RESOURCE NAME", "PROJECT", "DEMAND"}, 
        {"Demand.RESOURCE NAME", "Demand.PROJECT", "Demand.DEMAND"}),

//Transform the null records for those missing from one table or the other
    capFN = {"RESOURCE NAME", "PROJECT", "COST PER HOUR","CAPACITY"},
    demFN = {"Demand.RESOURCE NAME", "Demand.PROJECT", "Demand.DEMAND"},
    recs = Table.ToRecords(#"Expanded Joined"),
    xForm = List.Generate(
        ()=>[rec = recs{0}, idx=0],
        each [idx] < List.Count(recs),
        each [rec = if recs{[idx]+1}[RESOURCE NAME] = null or recs{[idx]+1}[Demand.RESOURCE NAME]= null then 
            let 
                rtl = Record.ToList(recs{[idx]+1}),
                xRtl = if rtl{0} = null then List.ReplaceRange(rtl,0,2, List.Range(rtl,4,2)) 
                    else List.ReplaceRange(rtl,4,2, List.Range(rtl,0,2)) 
            in Record.FromList(xRtl, List.Combine({capFN,demFN}))
            
                        
                        else recs{[idx]+1}, idx=[idx]+1],
        each [rec]),
    #"Converted to Table" = Table.FromList(xForm, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", 
        {"RESOURCE NAME", "PROJECT", "COST PER HOUR", "CAPACITY", "Demand.DEMAND"}, 
        {"RESOURCE NAME", "PROJECT", "COST PER HOUR", "CAPACITY", "Demand.DEMAND"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{
        {"RESOURCE NAME", type text}, {"PROJECT", type text}, 
        {"COST PER HOUR", Currency.Type}, 
        {"CAPACITY", Int64.Type}, {"Demand.DEMAND", Int64.Type}}),

//Add demand*cost column
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Demand Cost", each [COST PER HOUR]*[Demand.DEMAND], Currency.Type),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"COST PER HOUR"})
in
    #"Removed Columns1"

=>