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
ddorhout
Frequent Visitor

Distinctcount and totals per category in visuals

Dear PowerBI community,

 

I am facing an issue with a visualization (stacked column). I am not sure if I need to make a new row…

I would like to use distinct count of my rows within my columns. I think it is explained best by giving an example:

 

I use something like this kind of dataset:

DummyX

UserID

Department

Yes

1

X

No

1

X

Yes

1

X

No

2

X

No

2

X

Yes

2

X

Yes

3

Y

Yes

3

Y

Yes

3

Y

No

4

Y

Yes

4

Y

 

I would like to summarize how many people are having a "No" in the first column, compared to the total number of Users per department.

If there is one row value in which there is a "No", then the count function should judge a user to be only counted as a "No".

 

So a figure (it is supposed to be a stacked column) would look then like the following, stacked on each other.

 

 

1x Yes

2x No

 

1x No

X

 

Y

 

At the moment, by using the distinctcount functionality in my visualization I get a visualization of the following in which some users are counted double if they have both a "Yes" and a "No":

 

2x Yes

 

2x Yes

2x No

 

1x No

X

 

Y

 

I hope you could help me out… 🙂

 

Best,

Doeke

1 ACCEPTED SOLUTION
ddorhout
Frequent Visitor

Thank for your reply! I understand that my explanation was not totally clear...

Eventually, I found the solution myself.

 

I combined two measures in my table:

 

1.

Count only Yes=
VAR __BASELINE_VALUE =
    CALCULATE(
        DISTINCTCOUNT('Table'[UserID]),
        'Table'[DummyX]
            IN { "No" }
    )
VAR __MEASURE_VALUE = DISTINCTCOUNT('Table'[UserID])
RETURN
    IF(NOT ISBLANK(__MEASURE_VALUE), __MEASURE_VALUE - __BASELINE_VALUE)
 
2.
Then I also made a count for the number of "No":
Count only No =
VAR __BASELINE_VALUE =
    CALCULATE(
        DISTINCTCOUNT('Table'[UserID]),
        'Table'[DummyX]
            IN { "No" }
    )
RETURN
__BASELINE_VALUE

 

 

Anyway, thanks for your help! 🙂

 

View solution in original post

3 REPLIES 3
ddorhout
Frequent Visitor

Thank for your reply! I understand that my explanation was not totally clear...

Eventually, I found the solution myself.

 

I combined two measures in my table:

 

1.

Count only Yes=
VAR __BASELINE_VALUE =
    CALCULATE(
        DISTINCTCOUNT('Table'[UserID]),
        'Table'[DummyX]
            IN { "No" }
    )
VAR __MEASURE_VALUE = DISTINCTCOUNT('Table'[UserID])
RETURN
    IF(NOT ISBLANK(__MEASURE_VALUE), __MEASURE_VALUE - __BASELINE_VALUE)
 
2.
Then I also made a count for the number of "No":
Count only No =
VAR __BASELINE_VALUE =
    CALCULATE(
        DISTINCTCOUNT('Table'[UserID]),
        'Table'[DummyX]
            IN { "No" }
    )
RETURN
__BASELINE_VALUE

 

 

Anyway, thanks for your help! 🙂

 

YukiK
Impactful Individual
Impactful Individual

Glad to hear that! Please consider giving a thumbs up to my reply if that helped 🙂

YukiK
Impactful Individual
Impactful Individual

I'm not sure if I understand what your final result table looks like, but here is a DAX measure to unique users who have "No" value in the first column.

Unique Users with At Least 1 No =
VAR __Users =
ADDCOLUMNS(
SUMMARIZE(
'Table',
'Table'[UserID]
),
"@MinDummy", CALCULATE( MINX( 'Table', 'Table'[DummyX] ) )
)
VAR __Res =
CALCULATE(
[Total Unique Users],
FILTER( __Users, [@MinDummy] = "No" )
)
RETURN
__Res


If this helps, please give it a thumbs up!

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.