I have a table Table1:
F1 | F2
-------
a | 1
a | 2
b | 1
c | 2
I would like to define a measure MyMeasure that would allow me to generate a table:
F2 | Count
----------
1 | 2
2 | 1
Where the values in Count would come from CUBEVALUE function like:
=CUBEVALUE("ThisWorkbookDataModel","[Measures].[MyMeasure]","[Table1].[F2].&[1]")
=CUBEVALUE("ThisWorkbookDataModel","[Measures].[MyMeasure]","[Table1].[F2].&[2]").
The logic of MyMeasure should be:
1) Find minimum value F2 for each group in F1 (a -> 1, b -> 1, c -> 2).
2) Distinct count items in F1 for a specified value from the previous point.
I was able to do it using a helper column in data model but I would like to achieve it with with a single measure.
The most recent attempt is:
=COUNTROWS(
GENERATE(
all(Table1[F2])
,SUMMARIZE(
all(Table1),Table1[F1],"sth",min(Table1[F2])
)
)
)
As I understand I am messing up the context and as a result I am getting:
F2 | Count
----------
1 | 6
2 | 6
In T-SQL I can generate the output using a query:
select distinct
t1.F2
,count(*) over (partition by t1.F2)
from (select distinct F2 from Table1) t1
right join (select F1, min(F2) as MyMin from Table1 group by F1) t2
on t1.F2 = t2.MyMin