Excel Power Pivot通过多对1,然后从1对多的关系集聚合数据

问题描述 投票:0回答:1

我在功率枢轴中有2个大桌子,我正在尝试使库存建造等级与压碎的库存等级保持一致。请参阅示例。我可以创建包含压碎品级的数据透视表,但是我无法找到正确的方法来提高库存品级,尽管在对接示例中,对帐显示为绿色。

感谢您寻求帮助simplitied example of what I am attempting

excel relationship one-to-many powerpivot
1个回答
0
投票

在Power Query中,创建您的查找表。

1)独特的破碎机,ID2)日期,ID

如果需要,这里有一个创建日期表的功能。调用该函数以获取日期列之后,为ID添加另一列。

/*--------------------------------------------------------------------------------------------------------------------
    PQ Create a Dates Table, returning a single column of dates.  

    Inputs:
    Start Date    | Enter the year as yyyy, month as mm, day as dd
    End Date      | Enter the year as yyyy, month as mm, day as dd
    Increments    | One row will be returned per increment. 

    Author:  Jenn Ratten

    Edits:   
    07/16/18      | Modified query copied from the internet.
    10/01/19      | Converted to a function.
--------------------------------------------------------------------------------------------------------------------*/

let

    fDatesTable = (StartYear as number, StartMonth as number, StartDay as number, EndYear as number, EndMonth as number, EndDay as number, IncrementDays as number, IncrementHours as number, IncrementMin as number, IncrementSec as number) as table =>

    let    

        StartDate = #date(StartYear,StartMonth,StartDay),
        EndDate = #date(EndYear,EndMonth,EndDay),
        Increments = #duration(IncrementDays,IncrementHours,IncrementMin,IncrementSec),
        DatesTable = Table.FromColumns({List.Dates(StartDate, Number.From(EndDate) - Number.From(StartDate), Increments)}, type table[Date]),
        ChangeType = Table.TransformColumnTypes(DatesTable,{{"Date", type date}})

    in

        ChangeType
in

    fDatesTable

将所有表加载到数据模型。

转到Power Pivot,图视图并创建您的关系。

  • 查找破碎机到数据表1和2
  • 对数据表1和2的查找日期

转到数据表1和2上的数据视图,为查找ID添加2个新列。您可以通过单击第一个单元格并使用此语法来一次指定列标题和公式,然后按Enter或单击公式栏中的复选标记。

Dates Lookup ID:=RELATED(lookup_dates[ID])
Crusher Lookup ID:=RELATED(lookup_crusher[ID])

可选,但很好的做法。...右键单击刚创建的新字段,然后选择“从客户端工具隐藏”。同时在两个数据表上隐藏日期和粉碎程序字段,并在两个查找表上隐藏ID字段。当您创建数据透视表以汇总多个表中的数据时,您放置在数据透视表上的文本字段应该是共享的字段(也就是查找表)。这有助于最大程度地减少总计与实际在表上看到的金额不匹配的数据透视。如果您隐藏字段,它会提醒您这一点。当然也有例外,但这是一个很好的经验法则。

现在创建度量以求和以及您想要的任何其他数学计算的总和。通过这些措施,从简单开始,然后让枢轴进行切片。将度量放入数据透视表的“值”部分。

Sum of Source Tons:=sum(Table1[Tons])

Sum of Destination Tons:=sum(Table2[Tons])
© www.soinside.com 2019 - 2024. All rights reserved.