계산된 측정값은 사용될 때마다 계산되는 명명된 DAX 식입니다.
계산 측정값 표현
AMO의 계산 측정값
AMO를 사용하여 테이블 형식 모델 계산 측정값을 관리하는 경우 논리 계산 측정값 개체와 개체의 개체에 Command 정의된 측정값 간에 일대일 일치가 MdxScript 있습니다. 각 계산 측정값 은 개체 내의 CREATE MEASURE 식으로 Command 정의되고 세미콜론으로 구분됩니다. 테이블 형식 모델의 계산된 모든 측정값은 개체의 한 명령 개체에 있는 컬렉션 CREATE MEASURE 문자열에 MdxScript 해당합니다. 계산된 각 측정값에 대해 을 사용한 일대일 매핑이 있습니다 CalculationProperty.
다음 코드 조각에서는 계산된 측정값을 만드는 방법을 보여 있습니다.
private void addCalculatedMeasure(
AMO.Cube modelCube
, string cmTableName
, string cmName
, string newCalculatedMeasureExpression
)
{
//Verify input requirements
if (string.IsNullOrEmpty(cmName) || string.IsNullOrWhiteSpace(cmName))
{
MessageBox.Show(String.Format("Calculated Measure name is not defined."), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(newCalculatedMeasureExpression) || string.IsNullOrWhiteSpace(newCalculatedMeasureExpression))
{
MessageBox.Show(String.Format("Calculated Measure expression is not defined."), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
StringBuilder measuresCommand = new StringBuilder();
AMO.MdxScript mdxScript = modelCube.MdxScripts["MdxScript"];
//ToDo: Verify if measure already exits and ask user what wants to do next
if (mdxScript.Commands.Count == 1)
{
measuresCommand.AppendLine("-------------------------------------------------------------");
measuresCommand.AppendLine("-- Tabular Model measures command (do not modify manually) --");
measuresCommand.AppendLine("-------------------------------------------------------------");
measuresCommand.AppendLine();
measuresCommand.AppendLine();
mdxScript.Commands.Add(new AMO.Command(measuresCommand.ToString()));
}
else
{
measuresCommand.Append(mdxScript.Commands[1].Text);
}
measuresCommand.AppendLine(string.Format("CREATE MEASURE '{0}'[{1}]={2};", cmTableName, cmName, newCalculatedMeasureExpression));
mdxScript.Commands[1].Text = measuresCommand.ToString();
if (!mdxScript.CalculationProperties.Contains(cmName))
{
AMO.CalculationProperty cp = new AMO.CalculationProperty(cmName, AMO.CalculationType.Member);
cp.FormatString = ""; // ToDo: Get formatting attributes for the member
cp.Visible = true;
mdxScript.CalculationProperties.Add(cp);
}
try
{
modelCube.Update(AMO.UpdateOptions.ExpandFull, AMO.UpdateMode.UpdateOrCreate);
MessageBox.Show(String.Format("Calculated Measure successfully defined."), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (AMO.OperationException amoOpXp)
{
MessageBox.Show(String.Format("Calculated Measure expression contains syntax errors, or references undefined or missspelled elements.\nError message: {0}", amoOpXp.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
catch (AMO.AmoException amoXp)
{
MessageBox.Show(String.Format("AMO exception accessing the server.\nError message: {0}", amoXp.Message), "AMO to Tabular message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
catch (Exception)
{
throw;
}
}