2017-12-15 5 views
0

Iは、次のExcelのテーブルを有する:ネットワークフローデータベース

Sample Table in Excel

列A、B及びDは、(データ)が与えられています。他の列が計算されます。それぞれの列の式を以下に示します。列A、BおよびDを考える

Formula in each column of Excel Table

、パワークエリを使用して作成され、このテーブルを作成することができますか?

+0

これは私にとっては円形の定義のようです。列Fは、列Fを参照する列Cに関して定義される。 –

答えて

0

これは、List.Generate、List.Accumulate、またはRecursive関数の1つのループ機構で実行できます。

反復の回数が分かっているので、私はList.Accumulateを好む。

以下のクエリでは、List.Accumulateは、Sourceに追加する必要のあるフィールドのレコードのリストを作成します。

結果の表は、列の値のリストと新しい表の種類によって構成されます。

let 
    Source = Table1, 
    IncomingSupplies = List.Buffer(Source[Incoming Supply]), 
    GenerateFlow = 
     List.Accumulate(
      List.Skip(IncomingSupplies), 
      {[Beginning On Hand Inventory = Source[Starting Inventory]{0}, 
       Shipments = 0.5 * #"Beginning On Hand Inventory", 
       Ending On Hand = #"Beginning On Hand Inventory" + IncomingSupplies{0} - Shipments]}, 
      (Result,Supply) => 
       Result & 
       {[Beginning On Hand Inventory = List.Last(Result)[Ending On Hand], 
        Shipments = 0.5 * #"Beginning On Hand Inventory", 
        Ending On Hand = #"Beginning On Hand Inventory" + Supply - Shipments]}), 
    NewTableType = Value.Type(Table.AddColumn(Source,"Records",each [], type[])), 
    CombineSourceAndFlow = Table.FromColumns(Table.ToColumns(Source)&{GenerateFlow},NewTableType), 
    ExpandFlow = Table.ExpandRecordColumn(CombineSourceAndFlow, "Records", {"Beginning On Hand Inventory", "Shipments", "Ending On Hand"}), 
    Typed = Table.TransformColumnTypes(ExpandFlow,{{"Beginning On Hand Inventory", Int64.Type}, {"Shipments", Int64.Type}, {"Ending On Hand", Int64.Type}}), 
    Reordered = Table.ReorderColumns(Typed,{"Month", "Starting Inventory", "Beginning On Hand Inventory", "Incoming Supply", "Shipments", "Ending On Hand"}) 
in 
    Reordered 
+0

解決策をありがとう。よく働く!これがスケールするかどうかを確認する必要があります。 – mnoPQ