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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
lkrishnaprasad
Frequent Visitor

how to get only one occurrence of distinct count

Hi,

 

I have data like this

 

case | incident 

----------------

c1 , inc1

c2 , inc1

c3 , inc2

c4 , inc2

c5 , inc3

 

when I do a matrix /table with showing distinct count(incident) I get like this 

 

case | incident count

-----------------------

c1, 1

c2, 1

c3, 1

c4, 1

c5, 1

-----

    3

 

what I expect is 

 

case | incident count

-----------------------

c1, 1

c2, 0

c3, 0

c4, 1

c5, 1

-------

3

 

my total is correct, but each row is counting 1 because the same incident is attached to 3 cases. 

 

please help how to get the correct count in rows as well as total.

 

Thanks

Krishna

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@lkrishnaprasad

 

One possible solution could be to add a calculated column assigning each incident to its first case

 

For example

 

Count =
VAR FirstCase =
    CALCULATE (
        FIRSTNONBLANK ( Table1[case], 1 ),
        ALLEXCEPT ( Table1, Table1[incident] )
    )
RETURN
    IF ( Table1[case] = FirstCase, 1, 0 )


county.png

View solution in original post

8 REPLIES 8
solentking1
New Member

Is there a way to do this in PowerQuery (M) for Excel?

Ashish_Mathur
Super User
Super User

Hi,

 

In your base data, do you not have a date column?


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

Hi,

 

Sorry for the late reply. There are no date columns. 

 

Here is my data.

 

PBIINCTable4.Column1Table4.Column2
PBI1INC1S1INC1
PBI1INC1S2INC1
PBI1INC2S3INC2
PBI1INC3S4INC3
PBI2INC4S5INC4
PBI2INC5NoDatanull
PBI3INC6NoDatanull
PBI3INC7NoDatanull
PBI3INC8NoDatanull

Zubair_Muhammad
Community Champion
Community Champion

@lkrishnaprasad

 

One possible solution could be to add a calculated column assigning each incident to its first case

 

For example

 

Count =
VAR FirstCase =
    CALCULATE (
        FIRSTNONBLANK ( Table1[case], 1 ),
        ALLEXCEPT ( Table1, Table1[incident] )
    )
RETURN
    IF ( Table1[case] = FirstCase, 1, 0 )


county.png

Thanks, it did work but if I have 1 more field?

 

Suppose if I have 1 more child field that relates to same PBI number, then what would be the formula to handle?

 

please see the output based on your query. 

inc-pbi.png

 

 

 

@lkrishnaprasad

 

Could you paste some data with expected outcome?

 

Just like you did at the beginning of the post

 

@lkrishnaprasad

 

Then we can use this column in a TABLE VISUAL

Please see file attached

 

county1.png

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors