Forum Discussion

tblackburn's avatar
tblackburn
Regular Visitor
8 years ago
Solved

Calculate days in current process step

Hi,

 

I'm trying to calculate the days each Work Order has spent in its current Process Step. The data is automatically appended every morning. Below is an example of the data for each Work Order, the last column (Days in Current Process Step) is what I'm trying to calculate automatically.

 

In reality this data set has multiple Work Orders for each day.

 

 

 

 

  • Hi tblackburn,

     

    Please create calculated columns using below DAX formulas in source table (in my test, it's named as 'Work Order').

    New Col1 =
    VAR lastdaypull =
        CALCULATE (
            MAX ( 'Work Order'[Day Pulled] ),
            ALLEXCEPT ( 'Work Order', 'Work Order'[Work Order] ),
            'Work Order'[Day Pulled] < EARLIER ( 'Work Order'[Day Pulled] )
        )
    RETURN
        IF (
            CALCULATE (
                LASTNONBLANK ( 'Work Order'[Current Process Step], 1 ),
                FILTER (
                    ALLEXCEPT ( 'Work Order', 'Work Order'[Work Order] ),
                    'Work Order'[Day Pulled] = lastdaypull
                )
            )
                <> 'Work Order'[Current Process Step],
            1,
            0
        )
    
    New Col2 = CALCULATE ( SUM ( 'Work Order'[New Col1] ), FILTER ( ALLEXCEPT ( 'Work Order', 'Work Order'[Work Order] ), 'Work Order'[Day Pulled] <= EARLIER ( 'Work Order'[Day Pulled] ) ) )
    Days in Current Process Step = RANKX ( FILTER ( 'Work Order', 'Work Order'[Work Order] = EARLIER ( 'Work Order'[Work Order] ) && 'Work Order'[New Col2] = EARLIER ( 'Work Order'[New Col2] ) ), 'Work Order'[Day Pulled], , ASC, DENSE )

     

    As resource data is automatically appended every morning, each time you open this report, please refresh report page manually, the table view will be updated to latest data.

     

    Regards,

    Yuliana Gu

4 Replies

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi tblackburn,

     

    Please create calculated columns using below DAX formulas in source table (in my test, it's named as 'Work Order').

    New Col1 =
    VAR lastdaypull =
        CALCULATE (
            MAX ( 'Work Order'[Day Pulled] ),
            ALLEXCEPT ( 'Work Order', 'Work Order'[Work Order] ),
            'Work Order'[Day Pulled] < EARLIER ( 'Work Order'[Day Pulled] )
        )
    RETURN
        IF (
            CALCULATE (
                LASTNONBLANK ( 'Work Order'[Current Process Step], 1 ),
                FILTER (
                    ALLEXCEPT ( 'Work Order', 'Work Order'[Work Order] ),
                    'Work Order'[Day Pulled] = lastdaypull
                )
            )
                <> 'Work Order'[Current Process Step],
            1,
            0
        )
    
    New Col2 = CALCULATE ( SUM ( 'Work Order'[New Col1] ), FILTER ( ALLEXCEPT ( 'Work Order', 'Work Order'[Work Order] ), 'Work Order'[Day Pulled] <= EARLIER ( 'Work Order'[Day Pulled] ) ) )
    Days in Current Process Step = RANKX ( FILTER ( 'Work Order', 'Work Order'[Work Order] = EARLIER ( 'Work Order'[Work Order] ) && 'Work Order'[New Col2] = EARLIER ( 'Work Order'[New Col2] ) ), 'Work Order'[Day Pulled], , ASC, DENSE )

     

    As resource data is automatically appended every morning, each time you open this report, please refresh report page manually, the table view will be updated to latest data.

     

    Regards,

    Yuliana Gu

    • popov's avatar
      popov
      Resolver III

      Hello!
      Try this formula of calculate column

      Days in Current Process Step =
      CALCULATE (
          COUNTROWS ( Table ),
          FILTER (
              Table,
              Table[Day Pulled] <= EARLIER ( Table[Day Pulled] )
                  && Table[Work order] = EARLIER ( Table[Work order] )
                  && Table[Product Name] = EARLIER ( Table[Product Name] )
                  && Table[Serial Number] = EARLIER ( Table[Current Process Step] )
                  && Table[Current Process Step] = EARLIER ( Table[Current Process Step] )
          )
      )