You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Power Query M代码为多公司NAV数据添加公司标识自定义列?

Add Static Company Identifier Column in Power Query M for Dynamics NAV Data

Absolutely! You can easily add that custom "Company" column with a fixed identifier using Power Query M. Here's how to modify your existing code to achieve the exact output you're looking for:

Modified Code with Company Column

let 
    Source = Sql.Databases("xx.x.x.x"), 
    zzz_LIVE = Source{[Name="NAVzzz_LIVE"]}[Data], 
    #"COMPANY1$G_L Entry" = zzz_LIVE{[Schema="dbo",Item="COMPANY1$G_L Entry"]}[Data],
    // Add custom column with fixed company name
    #"Added Company Column" = Table.AddColumn(#"COMPANY1$G_L Entry", "Company", each "Company1")
in
    #"Added Company Column"

Breakdown of the Change

  • The Table.AddColumn function is the key here:
    1. First parameter: The target table you want to modify (#"COMPANY1$G_L Entry")
    2. Second parameter: The name of your new column ("Company")
    3. Third parameter: A function that returns the value for each row — since this is a fixed identifier for the entire table, we just return the static string "Company1"

Bonus: Optimize for Multiple Companies

If you plan to pull data from multiple NAV companies later, you can make the code more reusable by defining the company name as a variable. This way you only need to update one value when switching companies:

let 
    // Define company name as a variable for easy editing
    TargetCompany = "Company1",
    Source = Sql.Databases("xx.x.x.x"), 
    zzz_LIVE = Source{[Name="NAVzzz_LIVE"]}[Data], 
    // Use the variable to dynamically reference the table
    #"G_L Entry Table" = zzz_LIVE{[Schema="dbo",Item=TargetCompany & "$G_L Entry"]}[Data],
    // Reuse the variable for the company column value
    #"Added Company Column" = Table.AddColumn(#"G_L Entry Table", "Company", each TargetCompany)
in
    #"Added Company Column"

This will output exactly the table structure you showed, with the "Company" column populated with "Company1" for every row.

内容的提问来源于stack exchange,提问作者Adni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:55:45