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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
maashi
Frequent Visitor

Multi level distinct counting

I'm trying to count some customer complaints with multiple filters, and am a bit stumped on how to write this measure. 

 

Link to sample data:

Freight snapshot.xlsx

 

I need to count some freight complaints that only have freight related reasons and nothing else.

A unique Sales Order Number can have several lines, and not every line has to have the same Material Return Reason. I want a distinct count of sales orders that contain line(s) of freight, nothing else.  So in the sample data I do not want to count Sales Orders 2017867 or 2009388 because it contains freight and other defect reasons. But I want to count 2016014, 2011927, 2013299, 2009417, 2010615. If there are multiple lines in the same sales order, as long as all the lines are freight, I will count it. (2010615 is a good example of this) 

In other words, if I count the data set, I want the answer to be 5.

 

Counting all freight lines is easy with a distinct count and a freight filter : 

Freight Count =

CALCULATE(
            DISTINCTCOUNT(
                fact_NCP_Reporting[Sales Order No]),
                FILTER('fact_NCP_Reporting',
                'fact_NCP_Reporting'[NCP Reason Categories.Reason Category]="Freight")
                )
But how do I add a second filter in to look at any other lines the same sales order contains and see if it contains any other return reasons besides freight?

Thanks for your help
1 ACCEPTED SOLUTION
Rakesh1705
Resolver III
Resolver III

1st created the sales order repeatation count

Rakesh1705_0-1722181849085.png

Freight count with respect to sales order no is calculated

Rakesh1705_1-1722181887097.png

Freight count and sales order repeatation number is compared

Rakesh1705_2-1722181921511.png

Net sales order number is calculated

Rakesh1705_3-1722181952711.png

If this solves your problem then accept the same as your solution

View solution in original post

3 REPLIES 3
Rakesh1705
Resolver III
Resolver III

1st created the sales order repeatation count

Rakesh1705_0-1722181849085.png

Freight count with respect to sales order no is calculated

Rakesh1705_1-1722181887097.png

Freight count and sales order repeatation number is compared

Rakesh1705_2-1722181921511.png

Net sales order number is calculated

Rakesh1705_3-1722181952711.png

If this solves your problem then accept the same as your solution

This worked perfectly. Thank you very much.

v-jialongy-msft
Community Support
Community Support

Hi @maashi 

 

First, you need to create a measure to calculate how many reasons one "sales no" has:

Reason count = 
VAR _no = SELECTEDVALUE(fact_NCP_Reporting[Sales Order No])

RETURN
CALCULATE(DISTINCTCOUNT(fact_NCP_Reporting[NCP Reason Categories.Reason Category]),FILTER(ALL(fact_NCP_Reporting),'fact_NCP_Reporting'[Sales Order No] = _no))

 

Then modify your original measure:

Freight Count = 
CALCULATE(
            DISTINCTCOUNT(
                fact_NCP_Reporting[Sales Order No]),
                FILTER(ALL('fact_NCP_Reporting'),
                'fact_NCP_Reporting'[NCP Reason Categories.Reason Category]="Freight"&&[Reason count]=1)
                )

 

 

Result:

vjialongymsft_0-1721959983067.png

 

 

 

 

 

 

Best Regards,

Jayleny

 

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.