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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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


Regards
Zubair

Please try my custom visuals

View solution in original post

7 REPLIES 7
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

@lkrishnaprasad

 

What is your expected result in this case?


Regards
Zubair

Please try my custom visuals
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


Regards
Zubair

Please try my custom visuals

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

 


Regards
Zubair

Please try my custom visuals

@lkrishnaprasad

 

Then we can use this column in a TABLE VISUAL

Please see file attached

 

county1.png


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.