2
votes

I would like to count the frequency of a value in a column for each row. In Excel my situation can be solved with this formula:

 =COUNTIF(I:I;I4)

In PowerBi Report and I have a table of students with a column, "Pääaine" (main subject). There are 81 distinct values in 1580 rows. I would like to calculate the number of similar students for each row (so that I can filter out the main subjects that have 4 or less students).

How do I do it in PowerBI?

With Calculated column like this I get 1580 for each cell:

 Pääaine lkm = 
 CALCULATE(
     COUNTROWS(Opiskelunkulku);
     FILTER(
         Opiskelunkulku;
         Opiskelunkulku[Pääaine] = Opiskelunkulku[Pääaine]
            )
     )
2

2 Answers

2
votes

You can use COUNTROWS() and EARLIER() to achieve this. EARLIER() returns the value for the specified column in the current row context.

Pääaine lkm =
COUNTROWS (
    FILTER (
        Opiskelunkulku,
        Opiskelunkulku[Pääaine] = EARLIER ( Opiskelunkulku[Pääaine] )
    )
)
2
votes

As an alternative to Rory's answer try CALCULATE() with ALLEXCEPT() as a filter. Like this:

Pääaine lkm =
CALCULATE (
    COUNTROWS ( Opiskelunkulku ),
    ALLEXCEPT ( Opiskelunkulku, Opiskelunkulku[Pääaine] )
)