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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
TM_
Frequent Visitor

Cannot Distinct Count Negative Values

Hello.

 

Unsure what the issue is here - I created a measure to find the difference between two sets of values ('A' and 'B' for simplicity):

 

Difference =

 IF(ISBLANK(A),
 BLANK(),
 (A- B))
 
I then made a table of these differences per 'Category' - some of these difference values are, of course, negative. However, when I tried creating a distinct count of these categories where the values were negative, the result comes back as (BLANK):

 

CategoryOutperformance =
    CALCULATE(
        DISTINCTCOUNT(
        'Test'[Category]
            ),
        FILTER(
            'Test',
                [Difference] < 0
        )
 
Why is this? And how can I amend to obtain the actual distinct count?
 
Thank you.
1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @TM_ ,

You can use the bellow DAX measure to achieve your goal:

CategoryOutperformance = 
CALCULATE(
    DISTINCTCOUNT('Test2'[Category]),
    FILTER(
        ADDCOLUMNS(
            VALUES('Test2'[Category]),
            "Difference",
            VAR A = CALCULATE(SUM('Test2'[Value]), 'Test2'[Subcategory] = "A")
            VAR B = CALCULATE(SUM('Test2'[Value]), 'Test2'[Subcategory] = "B")
            RETURN IF(ISBLANK(A), BLANK(), A - B)
        ),
        [Difference] < 0
    )
)

 

Your output should look like this:

Bibiano_Geraldo_0-1737725059276.png

 

View solution in original post

4 REPLIES 4
Bibiano_Geraldo
Super User
Super User

Hi @TM_ ,

You can use the bellow DAX measure to achieve your goal:

CategoryOutperformance = 
CALCULATE(
    DISTINCTCOUNT('Test2'[Category]),
    FILTER(
        ADDCOLUMNS(
            VALUES('Test2'[Category]),
            "Difference",
            VAR A = CALCULATE(SUM('Test2'[Value]), 'Test2'[Subcategory] = "A")
            VAR B = CALCULATE(SUM('Test2'[Value]), 'Test2'[Subcategory] = "B")
            RETURN IF(ISBLANK(A), BLANK(), A - B)
        ),
        [Difference] < 0
    )
)

 

Your output should look like this:

Bibiano_Geraldo_0-1737725059276.png

 

rajendraongole1
Super User
Super User

Hi @TM_  - It’s possible that there’s an issue with the current context or filter. Let’s try to modify your CategoryOutperformance measure to ensure it’s correctly filtering and counting the distinct categories.

 

CategoryOutperformance =
CALCULATE(
DISTINCTCOUNT('Test'[Category]),
FILTER(
'Test',
NOT(ISBLANK([Difference])) && [Difference] < 0
)
)

 

I hope it works, If you’re still having trouble, feel free to share more details or a sample of your data.

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi @rajendraongole1 

 

Thank you for your reply! Unfortunately, this hasn't worked.

 

More detail below, data set: 

 

TM__3-1737647145636.png

 

I used this formula in full to calculate the Difference where there was a value in Subcategory A: 

 

Difference =
 VAR A =
 CALCULATE(
 SUM(
    Test2[Value]),
    Test2[Subcategory] = "A"
 )

 VAR B =
 CALCULATE(
 SUM(
    Test2[Value]),
    Test2[Subcategory] = "B"
 )

 RETURN

 IF(ISBLANK(A),
 BLANK(),
 (A - B))
 
Result works fine it seems; difference is calculated correctly: 
 
TM__4-1737647221857.png
Then as per your reply, I tried this formula to distinct count the difference values which were negative - as above, this should be 6 but instead I get (Blank) on the card visualisation:
 
CategoryOutperformance =
    CALCULATE(
        DISTINCTCOUNT(
        'Test2'[Category]
            ),
        FILTER(
            'Test2',
                NOT(ISBLANK([Difference])) && [Difference] < 0
        )
    )
 
TM__5-1737647384165.png
Where could I be going wrong?
 
Thank you. 

 

Anonymous
Not applicable

Hi @TM_ ,

You can create two measures as below to get it, please find the details in the attachment.

Measure = 
VAR _diff = [Difference]
RETURN
    CALCULATE ( DISTINCTCOUNT ( 'Test2'[Category] ), FILTER ( 'Test2', _diff < 0 ) )
CategoryOutperformance = SUMX ( VALUES ( Test2[Category] ), [Measure] )

vyiruanmsft_0-1737688068815.png

Best Regards

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.