Table of Contents

创建 M 分区

脚本用途

如果您想创建新的动态 M 参数,用于 Power Query 查询(M 分区或共享表达式)。

脚本

创建新的 M 分区

// This script creates a new M parameter in the 'Shared Expressions' of a model.
//
// Create a new shared expression called "New Parameter"
Model.AddExpression( 
    "New Parameter", 
    @"
""Parameter Text"" meta
[
	IsParameterQuery = true,
	IsParameterQueryRequired = true,
	Type = type text
]"
);

// Provides an output informing how to configure and use the parameter
Info ( 
    "Created a new Shared Expression called 'New Parameter', which is an M Parameter template." + 
    "\n------------------------------------------------------\n" + 
    "To configure:" +
    "\n------------------------------------------------------\n    " + 
    "1. Replace the text 'New Parameter' with the desired parameter value\n    " +
    "2. Set the data type appropriately\n    " +
    "3. Replace any values found in the M partitions with the parameter reference." );

说明

此代码片段会在“共享表达式”中创建一个新的 M 参数,并可在 M 分区的 Power Query 中引用。

输出示例

An example of the Info box that appears to inform the user that the M Parameter was successfully created, and recommending next steps to configure / use it in the M Partitions.
图 1: Info 提示框示例:用于告知用户已成功创建 M 参数,并建议下一步如何在 M 分区中配置/使用它。