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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jaybertx
Regular Visitor

Compare Dates by Index

Hi everyone!

 

I have been hammering on this for a few weeks and every time I think I have the answer I end up going in circles. Hopefully someone can help point me in the right direction. I have data that looks like this: 

 

Payroll IDOrientation DateOrientation IndexCount?
12311/1/20231Y
12321/14/20231Y
12328/14/20232Y
123210/14/20233N
12333/1/20231Y
12338/1/20232N

 

The "Count" column does not currently exist but I would like it to be generated automatically. Rules for Y/N: 

 

1. I would always like to count the index of 1

2. For a specific payroll ID I would like to count an orientation if there is 6 months or more between them. I would only compare 1 to 2, 2 to 3, 3 to 4, etc. 

 

Any help would be appreciated! Thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @jaybertx ,

 

Here are the steps you can follow:

1. Create calculated column.

Count =
var _next=
MAXX(
    FILTER(ALL('Table'),'Table'[Payroll ID]=EARLIER('Table'[Payroll ID])&&'Table'[Orientation Index]=EARLIER('Table'[Orientation Index])+1),[Orientation Index])
var _nextdate=
MAXX(
    FILTER(ALL('Table'),
    'Table'[Payroll ID]=EARLIER('Table'[Payroll ID])&&'Table'[Orientation Index]=_next),[Orientation Date])
var _datediff=
DATEDIFF(
    'Table'[Orientation Date],_nextdate,MONTH)
return
IF(
    'Table'[Orientation Index]=1,"Y",
    IF(
        _datediff>=6,"Y","N"))

2. Result:

When [Payroll ID]=1233 and [Orientation Index]=2, the date difference from [Orientation Index]=3 is only 2 months, which is less than 6 months, so it is N

vyangliumsft_0-1699586189621.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @jaybertx ,

 

Here are the steps you can follow:

1. Create calculated column.

Count =
var _next=
MAXX(
    FILTER(ALL('Table'),'Table'[Payroll ID]=EARLIER('Table'[Payroll ID])&&'Table'[Orientation Index]=EARLIER('Table'[Orientation Index])+1),[Orientation Index])
var _nextdate=
MAXX(
    FILTER(ALL('Table'),
    'Table'[Payroll ID]=EARLIER('Table'[Payroll ID])&&'Table'[Orientation Index]=_next),[Orientation Date])
var _datediff=
DATEDIFF(
    'Table'[Orientation Date],_nextdate,MONTH)
return
IF(
    'Table'[Orientation Index]=1,"Y",
    IF(
        _datediff>=6,"Y","N"))

2. Result:

When [Payroll ID]=1233 and [Orientation Index]=2, the date difference from [Orientation Index]=3 is only 2 months, which is less than 6 months, so it is N

vyangliumsft_0-1699586189621.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

amitchandak
Super User
Super User

@jaybertx , Based on what I got. A new column

 

New column =

Var _max  = maxx(filter(Table, [Payroll ID] = earlier([Payroll ID]) && [Orientation Date] < earlier([Orientation Date])  )[Orientation Date] )

return

if(datediff(_max, [Orientation Date], month) >= 6, "Y", "N")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors