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
Applicable88
Impactful Individual
Impactful Individual

Count Ordernumbers base on duplicate value

Hello,

 

I have following table:

OrdernumberDateStatus
888825.04.2021A
777725.04.2021A
111125.04.2021A
111125.04.2021D
222225.04.2021A
222225.04.2021D
333325.04.2021A
333325.04.2021D
444425.04.2021D
555525.04.2021D

Order numbers with D are the orders which we accomplished to ship out today already. Status A orders are the delayed leftovers from yesterday which "had" to become D later today. Thats the reason these orders have an "A" and an "D" counterpart. Thats the reason why orders with "A" only gets updated  once a day, otherwise they would be overwritten with "D" and you can't tell the real perfomance of today. "A" orders are not counting to the performance of today, because they should have finished yesterday.

 

So to calculate the performance of today istn't just count of D orders minus count of A orders. Its actually count all "D" orders minus the "D"orders which also has a "A" Status counterpart. 

In above sample data 2 should be the outcome. 

I hope it was not too confusing. 
Thank you in advance!
Best.

 

 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hello @Applicable88 

 

A measure like this should work:

Performance = 
VAR Orders_D = 
    CALCULATETABLE ( 
        VALUES ( Orders[Ordernumber] ),
        Orders[Status] = "D"
    )
VAR Orders_A = 
    CALCULATETABLE ( 
        VALUES ( Orders[Ordernumber] ),
        Orders[Status] = "A"
    )
RETURN
    COUNTROWS ( EXCEPT ( Orders_D, Orders_A ) )

The logic is to take the set of Orders with Status D and remove Orders with Status A using EXCEPT. Any orders with Status A but not Status D will not influence the result.

 

With your sample data,

  • Orders_D = { 1111, 2222, 3333, 4444, 5555 }
  • Orders_A = { 1111, 2222, 3333, 7777, 8888 }
  • EXCEPT ( Orders_D, Orders_A ) = { 4444, 5555 }

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

3 REPLIES 3
OwenAuger
Super User
Super User

Hello @Applicable88 

 

A measure like this should work:

Performance = 
VAR Orders_D = 
    CALCULATETABLE ( 
        VALUES ( Orders[Ordernumber] ),
        Orders[Status] = "D"
    )
VAR Orders_A = 
    CALCULATETABLE ( 
        VALUES ( Orders[Ordernumber] ),
        Orders[Status] = "A"
    )
RETURN
    COUNTROWS ( EXCEPT ( Orders_D, Orders_A ) )

The logic is to take the set of Orders with Status D and remove Orders with Status A using EXCEPT. Any orders with Status A but not Status D will not influence the result.

 

With your sample data,

  • Orders_D = { 1111, 2222, 3333, 4444, 5555 }
  • Orders_A = { 1111, 2222, 3333, 7777, 8888 }
  • EXCEPT ( Orders_D, Orders_A ) = { 4444, 5555 }

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Thank you again @OwenAuger .

 

I found the problem. My last function was not right. A simple sum was enough and afterwards it worked out.

Best. 

@OwenAuger ! 

Thank you very much it works for the ordernumbers. 

I forgot to mention that I have another column (Positions of deliveries) which this time needs to be sum up base on the above logic, so only sum these delivery positions of the 2 orders. I tried with calculate sum and sumx as well, but I always get an error or empty value and sometimes a much bigger number. As you can see I changed the last line to sum instead of count:

 

Performance = 
VAR Orders_D = 
    CALCULATETABLE ( 
        VALUES ( Orders[Ordernumber] ),
        Orders[Status] = "D"
    )
VAR Orders_A = 
    CALCULATETABLE ( 
        VALUES ( Orders[Ordernumber] ),
        Orders[Status] = "A"
    )
RETURN
calculate( SUMX(Orders,Orders[Deliverypositions]), EXCEPT ( Orders_D, Orders_A ) )

    

Do I need a comlete another formula to get sum the position?

 

 
I hope I can use same approach for the Deliverypositions as well.

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.