I am trying to calculate COUNT number of customers that bought an item, grouped by item category. <br>
I think I have managed mdx part of it, but when I create dynamic set and member in cube, it does not work as intended... I always get 1.
this is my MDX: [Measures].[Sold] is on lowest level SKU level and can be only 0 or 1
with set CC as filter( [CUSTOMERS].[Customer].[Customer] , [Measures].[Sold] > 0 )
member measures.C as
iif(
count(nonempty( CC, [Measures].[Sold])) = 0, null,
count(nonempty( CC, [Measures].[Sold]))
)
select {[Measures].[Sales], measures.C } on 0,
non empty
[MATERIALS].[Brand].allmembers
on 1
from (select ({ [CUSTOMERS].[Customer].&[1],
[CUSTOMERS].[Customer].&[2],
[CUSTOMERS].[Customer].&[3]},
[PERIOD].[Period].&[2019002]) ON 0 FROM CUBE)
I get results as expected, calculated measure C counts 3 customers bought at least one product from category 1, 2 customers from category 2, etc.
---------- Sales C
All.......... 78 3
CATEGORY.1....24 3
CATEGORY.2....18 2
CATEGORY 3.....9 2
CATEGORY 4....24 2
CATEGORY 5.....3 1
now, when I create dynamic set and new member in cube script, with exactly the same logic, I always get count=1... I do not get it, and it drives me nuts. I used the subcube because my main goal is to have that measure and cube ready for excel.
create dynamic set currentcube.[CC] as
filter([CUSTOMERS].[Customer].[Customer], [Measures].[SOLD] > 0 );
create member currentcube.[measures].[C_CUBE] as
iif(
count(nonempty([CC], [Measures].[SOLD])) = 0, null,
count( nonempty ( [CC], [Measures].[SOLD] ))
);
When I run the same MDX along with new measure, or without MDX gives me expected results, new measure member always returns 1, like if teh dynamic set had only one item....(?)
---------- Sales C C_CUBE
All.......... 78 3 1
CATEGORY.1....24 3 1
CATEGORY.2....18 2 1
CATEGORY 3.....9 2 1
CATEGORY 4....24 2 1
CATEGORY 5.....3 1 1
Could someone perhaps point in correct direction?
Thank you