Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
WimHenderickx
Frequent Visitor

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

 

1 ACCEPTED SOLUTION

@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

 

Fowmy_0-1739110650491.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

9 REPLIES 9
Fowmy
Super User
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:

Fowmy_0-1739103497373.png

 







Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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

WimHenderickx_0-1739105241316.png

 

@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.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

It goes wrong after the second row when there is no gap between the endDate and startdate

 

EmployeStartdateEndDateOrderIndexExpected
15-12-202213-3-202313-3-202311
114-3-202319-3-202313-3-202311
120-3-202310-4-202319-3-202321
111-4-202325-6-202310-4-202331
126-6-202317-1-202425-6-202341
118-1-202431-1-202417-1-202451
11-2-20246-2-202431-1-202461
17-2-20241-3-20246-2-202471
11-7-202431-7-202431-7-202482
11-8-202415-9-202431-7-202482
116-9-202429-10-202415-9-202492
216-3-202320-3-202320-3-202311
216-7-202319-7-202319-7-202311
31-4-20244-4-20244-4-202411
35-4-20249-4-20244-4-202411

@WimHenderickx 

Should this be 1, 2

2 16-3-2023 20-3-2023 20-3-2023 1 1
2 16-7-2023 19-7-2023 19-7-2023 1 1
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Yes you are right 

@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

 

Fowmy_0-1739110650491.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thanks for all your help.

nilendraFabric
Community Champion
Community Champion

@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)
)
)
)

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.