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

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

Reply
AriGooner
Frequent Visitor

Distinct Count with filter

Hi Everyone, 

Can somebody help me 

So I have a case like this, I'm trying to find a unique value from the table,
I'm trying to count every outlet code whose total sales are more than 0 (zero) then it is counted as 1,
otherwise if each code is not more than 0 then it is 0. the code i use is for active outlet


= CALCULATE(DISTINCTCOUNT(
(tabletrx[Kode Outlet]))
,tabletrx[Hl]>0)

But the problem is when the "kode outlet" have 2 transaction with value
example 1 and -2 still count as 1 but what i hope is 0 cause 1 - 2 = -1

12 REPLIES 12
Jos_Woolley
Solution Sage
Solution Sage

Hi,

Post a small example dataset together with expected result.

Regards

this is  simple dataset and what i expected for example.

 

AriGooner_1-1645689758402.png

so what i expect is every total qty of outlets is greater than 0 then outlet is counted as 1.

 

@AriGooner Please try this:-

Measure =
CALCULATE (
    DISTINCTCOUNT ( 'Table (4)'[Outlet Code] ),
    FILTER ( 'Table (4)', SUM ( 'Table (4)'[QTY] ) > 1 )
)

Output:-

Samarth_18_0-1645691023123.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

the result still not what i expect 
 

i try this,
= CALCULATE(DISTINCTCOUNT(tabletrx[Kode Outlet]),filter(tabletrx,tabletrx[Hl]>1))

 

but the result is same like
= CALCULATE(DISTINCTCOUNT(tabletrx[Kode Outlet]))

 

 

 

@AriGooner Use it like this:-

= CALCULATE(DISTINCTCOUNT(tabletrx[Kode Outlet]),filter(tabletrx,sum(tabletrx[Hl])>1))

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

still not working for me 😞

 

AriGooner_0-1645726348156.png

 

Hi @AriGooner ,

According to your description, here's my solution.

This is my sample data.

vkalyjmsft_0-1646035713421.png

Create a measure.

Active outlet = 
IF (
    SUMX (
        FILTER (
            ALL ( 'tabletrx' ),
            'tabletrx'[Kode Outlet] = MAX ( 'tabletrx'[Kode Outlet] )
        ),
        'tabletrx'[Hl]
    ) > 0,
    1,
    BLANK ()
)

Get the correct result.

vkalyjmsft_1-1646035824416.png

If you want the total to be 2, use a calculated column instead.

Column = 
IF (
    SUMX (
        FILTER (
            ALL ( 'tabletrx' ),
            'tabletrx'[Kode Outlet] = EARLIER ( 'tabletrx'[Kode Outlet] )
        ),
        'tabletrx'[Hl]
    ) > 0
        && 'tabletrx'[Hl] > 0,
    1,
    BLANK ()
)

Get the correct result.

vkalyjmsft_2-1646035935311.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

AriGooner_0-1649234122197.png

 

hi, i try your measure but why in my file for EARLIER is not working? may i am wrong? i already update my power bi in the desktop

Hi, Thanks for your advice.

i try your measure but in my data number less than 0 still counting as 1?

may im wrong?

 

AriGooner_1-1646128770345.png

 

 

Hi @AriGooner ,

How about only put Kode Outlet and HI in a table visual like me?

You can analyze why the result is wrong, it should be right as usual, compare your sample with mine or post the sample without sensitive information.

Best Regards,
Community Support Team _ kalyj

Samarth_18
Community Champion
Community Champion

Hi @AriGooner ,

 

Please try this:-

= CALCULATE(DISTINCTCOUNT(tabletrx[Kode Outlet]),SUM(tabletrx[Hl])>0)

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Thanks for advice, if i add SUM the measure can't working.

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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