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 create a table:
F2 | Count
----------
1 | 2
2 | 1
If the values ββin Count will come from the CUBEVALUE function, for example:
=CUBEVALUE("ThisWorkbookDataModel","[Measures].[MyMeasure]","[Table1].[F2].&[1]")
=CUBEVALUE("ThisWorkbookDataModel","[Measures].[MyMeasure]","[Table1].[F2].&[2]").
MyMeasure logic should be:
1) Find the minimum value of F2 for each group in F1 (a β 1, b β 1, c β 2).
2) Individual counting elements in F1 for a given value from a previous point.
I was able to do this using an auxiliary column in the data model, but I would like to achieve it with one measure.
Most recent attempt:
=COUNTROWS(
GENERATE(
all(Table1[F2])
,SUMMARIZE(
all(Table1),Table1[F1],"sth",min(Table1[F2])
)
)
)
As I understand it, I messed up the context, and as a result I get:
F2 | Count
----------
1 | 6
2 | 6
In T-SQL, I can generate 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