Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Countif in DAX or Power Query

Hi all,

 

Please help as i was not able to find solution for what i require.
I have dataset with repeating ID number and i need to count how many times it repeats in a dataset. Groupby does not work, as i need data to remain ungrouped.

 

My goal is to count how many ids i have that apear more thatn one time in a table. Preferably i would like to do it in DAX, but if i can create this calculation in power query, i will be able to easily do it in DAX.

 

Below is example of dataset i have.

 

What I have

What I need

ID

Countif

1

3

2

2

1

3

3

1

4

1

5

1

6

1

1

3

2

2

 

Any help is greatly appreciated

Regards

Filarap

 

  • Cmcmahan's avatar
    Cmcmahan
    7 years ago

    If all you need is a measure for a card that displays the count of IDs that appear 2+ times, that should be pretty easy.  I'm not sure why you're so against using summarization or groupings for a single measure, but here's how I would do it:

    CountMultiIDs = COUNTROWS(FILTER(ADDCOLUMNS( VALUES('Table'[ID]), "IDCount", CALCULATE(COUNTROWS('Table'))), [IDCount]>1))

    The tricky bit here is to use CALCULATE around the inner COUNTROWS so that the DAX re-evaluates the context at which it is counting.

10 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you mussaenda,

       

      This will give me total count of ids, where i need to filter distinct ids that apear in list more than once.

       

      From table provided, result should be 2 :

      IDs 1 and 2 apear more thatn once in a dataset.

       

      Hope this makes it clearer

      Filarap

      • mussaenda's avatar
        mussaenda
        Community Champion

        Power BI groups the ID though you choose do not summarize.

        As a workaround, I used an index to prevent it from grouping then counted the ids.

         

  • How about this?

     

    = CALCULATE(
    	COUNT(Table1[ID]),
    		FILTER(Table1,
    			Table1[ID] = EARLIER(Table1[ID])
    		)
    	)
    • Anonymous's avatar
      Anonymous
      Not applicable

      I tried using this, but for some reason, EARLIER does not recognise any column name.

       

      • sktneer's avatar
        sktneer
        Resolver I

        That's something strange.

        This is the output returned by that formula....