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

DAX to count number of rows with multiple conditions

Hi

Here is my order table;

Order NoSO LinesShipping Condition
1000110Ship as available
1000120Ship as available
1200210Ship complete
1200220Ship complete
1300110Ship as available
1300120Ship as available
1300130Ship as available
1400110Ship as available

 

If the shipping condition is 'Ship as available' then each of the order lines is treated separately. While if the order has the shipping condition as 'Ship complete' then the order is treated as 1 and all order lines need to ship together. This means in the above table I have 7 order lines.

 

I need assistance with the measures;

1. that counts the number of order lines based on shipping conditions, and

2. the other that just gives me the sum total of the count of order lines

 

Thanks and Regards

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please try the below measures, and check the attached pbix file.

 

Count based on the condition measure: = 
VAR available_table =
    FILTER ( Data, Data[Shipping Condition] = "Ship as available" )
VAR complete_table =
    FILTER (
        SUMMARIZE ( Data, Data[Order No], Data[Shipping Condition] ),
        Data[Shipping Condition] = "Ship complete"
    )
RETURN
    COUNTROWS ( available_table ) + COUNTROWS ( complete_table )

 

Count measure: = 
COUNTROWS( Data )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
JajatiDev
Helper I
Helper I

Hi Jihwan_Kim,

Thank you. The DAX function shared is working as expected.

 

Regards,

Jajati Dev

Jihwan_Kim
Super User
Super User

Hi,

Please try the below measures, and check the attached pbix file.

 

Count based on the condition measure: = 
VAR available_table =
    FILTER ( Data, Data[Shipping Condition] = "Ship as available" )
VAR complete_table =
    FILTER (
        SUMMARIZE ( Data, Data[Order No], Data[Shipping Condition] ),
        Data[Shipping Condition] = "Ship complete"
    )
RETURN
    COUNTROWS ( available_table ) + COUNTROWS ( complete_table )

 

Count measure: = 
COUNTROWS( Data )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.

Top Solution Authors