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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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.


Follow on LinkedIn
@ 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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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