Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
harvis
Frequent Visitor

DAX Count Only the first occurence of a value

Hi,

I have a large dataset containing numbers that can be duplicate by date, month and so on. The numbers have an unique ID. I simplified the dataset here

The last number in uniqueid is not imcremental in mye real dataset. The dates is usually different as well.

2018-05-04 21_51_23-6. Gjentangende Henvendelser calculate - Power BI Desktop.png

What I want to do is to count the first (or one of the occurence) of the number column where there are repeating numbers. Then I need to get the row count as well as total correct. In this example the total should be 2 (the first row (or one of them) of the 123 number, the same for 666 number).

 

I have tried several formulas, the formulas in the picture underneath is

 

fcount = COUNT(samplenumbers[numbers])

 

distinctcount = DISTINCTCOUNT(samplenumbers[numbers])

 

repeatingcount = CALCULATE(COUNT(samplenumbers[numbers]);ALL(samplenumbers);VALUES(samplenumbers[numbers]);VALUES(Dato))

 

repeatingsum=
SUMGjentagendeKunderTotalSum = IF([GjentagendeKunderALL]>1;1;BLANK())

 

2018-05-04 22_00_38-6. Gjentangende Henvendelser calculate - Power BI Desktop.png

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

Try this measure

 

=CALCULATE(COUNTROWS(samplenumbers),FILTER(SUMMARIZE(VALUES(samplenumbers[numbers]),[numbers],"ABCD",COUNTROWS(samplenumbers)),[ABCD]>1))

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

 

Try this measure

 

=CALCULATE(COUNTROWS(samplenumbers),FILTER(SUMMARIZE(VALUES(samplenumbers[numbers]),[numbers],"ABCD",COUNTROWS(samplenumbers)),[ABCD]>1))

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you, this worked well. The only change i did was changing the first COUNTROWS to DISTINCTCOUNT.

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

Try using a COUNTROWS over a SUMMARIZE. If you only want rows that have more than one row, you could use a COUNT in your SUMMARIZE and use a FILTER on it before passing it to COUNTROWS.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.