如何处理数据透视表中的重复条目以及如何在 Excel 仪表板中填充查询

2024-02-09

我有两张桌子capacity and demand

容量表如下所示:

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

需求表如下所示:

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 query 合并了这两个表资源名称并尝试生成下面的数据透视表。

Pivot table screenshot
Pivot table screenshot

我在两个表中的共同字段是“资源名称”,我正在尝试在数据透视表中构建什么,该数据将在带有切片器的仪表板中进一步使用。尝试构建这样的仪表板。

Dashboard screenshot
Dashboard Screenshot

挑战点:

  • 无法捕获产能小时数和总产能成本,成本不断重复。其他值来自Hours & Cost根据上面的数据透视表,部分是很好的需求时间和总需求。

Power Query 合并屏幕截图

决赛桌截图

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

最终表格如下:

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

Queries:
容量表

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"

需求表

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"

决赛桌

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"

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


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

  • 根据连接两个表{"RESOURCE NAME","PROJECT"} using JoinKind.FullOuter
  • 展开表格并在其中“填充空值”PROJECT and RESOURCE NAME容量或需求表中缺少条目的行的列
  • 添加需求*成本列。
  • 清理完毕后,您可以保存并加载到数据透视表。

M Code

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"

=>

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何处理数据透视表中的重复条目以及如何在 Excel 仪表板中填充查询 的相关文章

随机推荐