cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Running count with multiple conditions

Hi,

 

Below is a simple example of the calculated column I am trying to create.

Last row showing the running count based on product and customer being the same. Order Qty is not relevant.

 

ProductCustomerOrder QtyCount
A12351
A12352
A12353
B45651
C45651
C45652
 

Thanks,

 

1 ACCEPTED SOLUTION
Super User III
Super User III

Hi @rhys1987 

You need to first add an index column to the table to indicate precedence. Otherwise there is no way to differentiate those rows in your count. You can do that easily in PQ. Then your calculated column:

 

Col =
CALCULATE (
    COUNT ( Table1[Product] ),
    ALLEXCEPT ( Table1, Table1[Product], Table1[Customer] ),
    Table1[Index] <= EARLIER ( Table1[Index] )
)

 

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

1 REPLY 1
Super User III
Super User III

Hi @rhys1987 

You need to first add an index column to the table to indicate precedence. Otherwise there is no way to differentiate those rows in your count. You can do that easily in PQ. Then your calculated column:

 

Col =
CALCULATE (
    COUNT ( Table1[Product] ),
    ALLEXCEPT ( Table1, Table1[Product], Table1[Customer] ),
    Table1[Index] <= EARLIER ( Table1[Index] )
)

 

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors