简体   繁体   中英

MDX Calculated Measure

Below is my requirement in the picture

样本数据

The 1st table is at least granularity.The avg is calculated by Date + Place .So the avg is 565 = (2865/5) .

Coming to the second table.The avg for place 702 is 114 which is right and for 704 it is 866 which is also right.But the final ans is the same as the avg for all 5 records.

But my output should be like avg at Date + Place level for single Date + Place but when two places are selected it should avg at place level but sum at the total output..the final value should be 980 (sum(114+866))

Can someone have a solution for this?

As with any average in SSAS Multidimensional you will need to create two physical measures. The first is a Sum of A which is AggregateFunction=Sum. The second is a Count of Rows which is AggregateFunction=Count.

The quicker way to implement your calculation is with this calculated measure:

SUM(
 EXISTING [Place].[Place].[Place].Members,
 DIVIDE( [Measures].[Sum of A], [Measures].[Count of Rows] )
)

However if you want to get better performance and properly handle multi-select filters then create a physical measure called Avg A which is AggregateFunction=Sum off a new column in your SQL table which is always 0. Then overwrite the values in that measure with the following scope statement:

SCOPE([Place].[Place].[Place].Members);
     [Measures].[Avg A] = DIVIDE( [Measures].[Sum of A], [Measures].[Count of Rows] );
END SCOPE;

Try this:

AvgA = SUMX(SUMMARIZE(Table2, Table2[Place], "A", AVERAGE(Table2[A])), [A])

This will take the average A grouping by each Place and then sum them up for the subtotal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM