Search code examples
powerbidaxdaxstudio

DAX - Frequency of Selected Values as a calculated Column


I have a simple table here:

enter image description here

I need to make a measure that counts records grouped by the Number column.

Ideally:

enter image description here

I also need this measure to by dynamic for whatever records are selected. So if a subset of the table is being used: (Same example table, but with 2 less records) enter image description here

Then the ideal output would be: Now output for number '1' is 2 instead of 4. enter image description here

Some of the code I tried:

    ,"CNT",COUNTROWS(ALLSELECTED([Table1]))
,"Summz",SUMMARIZE(ALLSELECTED(Table1),"CNT",COUNTROWS(Table1))
,"CALC",CALCULATE(COUNT(Table1[Rownum]),ALLEXCEPT(Table1,Table1[Number]))
,"CALCII",CALCULATE(
            SUMX(
                ADDCOLUMNS(
                    SUMMARIZE(Table1,Table1[Rownum])
                ,"Freq",DISTINCTCOUNT(Table1[Number])
                ),
                [Freq])
                ,REMOVEFILTERS(Table1[Rownum])
            )

enter image description here

I feel like I'm close but not getting it. Any help would be appreciated!

Thank you


Solution

  • Try this.

    Freq = CALCULATE( COUNT(Table1[Number]), ALLEXCEPT(Table1,Table1[Number]))