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
rrafferty37
Helper I
Helper I

Help with DAX conditional count of orders

Hello,

 

Looking for a bit of help with a measure I can't seem to quite get right.

 

I have a table that has sales order lines.  The Order # is repeated multiple times if there are different SKU's on the order.  My first step is I wanted to sum the amount of units on each order, excluding certain types of units.

 

first measure:  

Order Units = 

CALCULATE(
    SUM('Table 1'[Units Sold]),
    filter('Table 1',OR('Table 1'[Product Type]="Condition 1",'Table 1'[Product Type]="Condition 2")))
 
This does what I expect and seems to be working fine.  My next step is to count the number of orders that have 5 or more units on the order. This is where I am getting hung up.
 
Attempt 1:
Qualified Order Count =

CALCULATE(

    DISTINCTCOUNT('Table 1'[Order]),

    filter('Table 1',[Frames/Suns Sold] >=5 ))

 

I don't recieve any errors, but I do not get a count either, the column is blank. 

I tried passing the Order Units calculation directly into the filter of the above measure as well with no dice. 

 

End Result, I want to be able to see how many orders have 5 or more units (of a certain type) were placed over some period of time.

 

Thanks!

1 ACCEPTED SOLUTION

@Greg_Deckler Thanks Greg, I will be sure to include in the future. I actually found an answer:

 

Qualified Order Count = 

Var units = Order Units

Return

Calculate( 

    DistinctCount('Table 1',

   filter('Table 1', units >=5))

 

Passing the measure as a variable seems to do the trick, althought I am not 100% certain as to why. 

 

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

Sample data would be tremendously helpful to replicate and test. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thanks Greg, I will be sure to include in the future. I actually found an answer:

 

Qualified Order Count = 

Var units = Order Units

Return

Calculate( 

    DistinctCount('Table 1',

   filter('Table 1', units >=5))

 

Passing the measure as a variable seems to do the trick, althought I am not 100% certain as to why. 

 

@rrafferty37 ,

 

By the way, you may help accept solution. Your contribution is highly appreciated.

https://www.sqlbi.com/?s=variable

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.