Forum Discussion

WimHenderickx's avatar
WimHenderickx
Frequent Visitor
1 year ago
Solved

Index

Looking for formula that creates index as in example. Per employee ID it is checked whether between the notifications e.g. Enddate first line and Startdate 2nd line there is a day difference if there is no difference then the index remains the same if difference >1 day then the index is increased.

 

Employe StartDateEndDateIndex
11-1-20258-1-20251
19-1-202516-1-20251
11-2-20258-2-20252
11-3-20252-3-20253
24-2-20256-2-20251
23-3-20254-3-20252
25-3-20256-3-20252

 

  • Fowmy's avatar
    Fowmy
    1 year ago

    WimHenderickx 

    Please try now:

    Order = 
    VAR __CurrStartDate = Table03[StartDate]
    VAR __PrevEndDate =
        CALCULATE (
            MAX ( Table03[EndDate] ),
            Table03[EndDate] < __CurrStartDate,
            ALLEXCEPT ( Table03, Table03[Employe ] )
        )
    VAR __Result =
        IF (
            ISBLANK ( __PrevEndDate ),
            1,
            IF ( INT ( __CurrStartDate - __PrevEndDate ) <= 1, 0, 1 )
        )
    RETURN
        __Result



    Index = 
    VAR __Emp = Table03[Employe ]
    VAR __StartDate = Table03[StartDate]
    VAR __Result =
        CALCULATE (
            SUM ( Table03[Order] ),
            Table03[Employe ] = __Emp,
            Table03[StartDate] <= __StartDate,
            REMOVEFILTERS ( table03 )
        )
    RETURN
        __Result
    

     

     

9 Replies

  • WimHenderickx 

     

    Give it a try

     

    Index =
    1 +
    CALCULATE(
    SUMX(
    FILTER(
    YourTable,
    YourTable[Employee] = EARLIER(YourTable[Employee])
    && YourTable[StartDate] <= EARLIER(YourTable[StartDate])
    ),
    VAR currStart = YourTable[StartDate]
    VAR prevStart =
    CALCULATE(
    MAX(YourTable[StartDate]),
    FILTER(
    YourTable,
    YourTable[Employee] = EARLIER(YourTable[Employee])
    && YourTable[StartDate] < currStart
    )
    )
    VAR prevEnd =
    CALCULATE(
    MAX(YourTable[EndDate]),
    FILTER(
    YourTable,
    YourTable[Employee] = EARLIER(YourTable[Employee])
    && YourTable[StartDate] = prevStart
    )
    )
    RETURN
    IF(
    ISBLANK(prevEnd),
    0,
    IF(currStart - prevEnd > 1, 1, 0)
    )
    )
    )

  • Fowmy's avatar
    Fowmy
    Super User

    WimHenderickx 

    Create two calculated column to achieve this.
    1st Column:

    Order = 
    VAR __CurrStartDate = Table03[StartDate]
    VAR __CurrEndDate = Table03[EndDate]
    VAR __PrevEndDate = CALCULATE( MAX(Table03[EndDate]) , Table03[EndDate] < __CurrStartDate  , ALLEXCEPT(Table03, Table03[Employe ]) )
    RETURN
       IF(ISBLANK( __PrevEndDate) , __CurrEndDate , IF( INT(__CurrStartDate - __PrevEndDate) = 1 , __PrevEndDate , __CurrEndDate ))


    2nd Column:

    Index = 
    ROWNUMBER( ALL(Table03[Employe ],Table03[Order]) , ORDERBY( Table03[Order] ) , PARTITIONBY( Table03[Employe ] ))
    


    Result:

     







    • WimHenderickx's avatar
      WimHenderickx
      Frequent Visitor

      Thanks for the formula - but i have some problems - see below the result with these formula's

       

      • Fowmy's avatar
        Fowmy
        Super User

        WimHenderickx 

        Let me check it out, paste your sample data in the reply rather than sharing it as image.
        include two or three employees as well.