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
GomzeeR
Regular Visitor

Need Help with DAX formula to count Distinct for order numbers

Hi all,

 

I have a data set, where an order number can have either one or multiple lines associated with it.

Ex:
OrderNO     Type
12345           A

12345           B

12346           A

12347           B

12348           A

12348           B

I want to count all the order numbers that have either Type A or Type B only. I don't want to count Order numbers that have both Type A & Type B

 

Probably this is quite simple, but I am unable to achieve it.

 

Thanks in advice.

 

Kind regards,

 

Gowtham

6 REPLIES 6
wdx223_Daniel
Super User
Super User

=countrows(filter(values(table[order no]),calculate(distinctcount(table[type]))=1))

Hi Daniel,

This formula is not working for me, I need to measure count for rows that has Type A only(which is one in the sample data). Same for Type B.

 

Kind regards,

 

Gowtham

Samarth_18
Community Champion
Community Champion

HI @GomzeeR ,

 

You can use below code:-

Unique_count =
COUNTROWS (
    SUMMARIZE ( 'Table (2)', 'Table (2)'[OrderNO     ], 'Table (2)'[Type] )
)

 

Below would be output

 

Samarth_18_0-1626852023290.png

Hope you wanted the same output if not please share the expected output.

 

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

Hi Samarth,

 

Thanks for taking time to help me.

If I add another Order No that has only Type A, my expected output should be.

TypeA - 2

TypeB - 1 

 

Your suggested formula still shows, TypeA - 1 and TypeB - 2.

 

I want to display order numbers that have Only Type A or only Type B. I don't want to count Order numbers that have Both.

 

Hope you understood my expected output.

Hi Samarth,

 

Thanks for your reply.

 

I want a count for Type A to be 1 and Type B to be 1(From the example data).
Count of Type A(unique) = 1
Count of Type B(Unique) = 1

I want to count only rows that has either A or B not both.

 

Kind regards,

 

Gowtham

Hi @GomzeeR 

 

You can try below code it will help

 

Unique_count = 
COUNTROWS (
    FILTER (
        VALUES ( 'Table (2)'[Type] ),
        CALCULATE ( DISTINCTCOUNT ( 'Table (2)'[OrderNO     ] ) > 1 )
    )
)

 

 

Output:-

Samarth_18_0-1626855098705.png

 

Thanks

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

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.