Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Distinct count of values when there are corresponding multiple lines per value

I am trying to create a measure that count up the the number of Late  or   On Time orders.    The challenge is that each order can have multiple lines, some late, some on time.    I already have a ca...
  • AlexisOlson's avatar
    5 years ago

    How about a calculated column like this?

     

    OrderStatus =
    VAR AllStatus =
        CALCULATETABLE (
            VALUES ( Orders[On Time or Late] ),
            ALLEXCEPT ( Orders, Orders[Order] )
        )
    RETURN
        IF ( "Late" IN AllStatus, "Late", "On Time" )

     

    Once you have this, it should be straightforward to write measures to count distinct orders. E.g.

    LateOrderCount =
    CALCULATE ( DISTINCTCOUNT ( Orders[Order] ), Orders[OrderStatus] = "Late" )
  • Anonymous's avatar
    Anonymous
    5 years ago

    Thanks AlexisOlson  !      Your solution worked just fine....it was my error.   In my OrderCount measures I had accidentally picked "orderstatus" instead of just "order"  for the first expression.   Corrected measure is below.   

     

    OnTimeOrderCount =
    CALCULATE ( DISTINCTCOUNT ( ShippedOrdersALL_Query[Order] ), ShippedOrdersALL_Query[OrderStatus] = "On Time" )