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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Flag only later repeat values that occurred within a specific time period prior

I am trying to flag duplicate values but only from the first duplicate value that type. 

 

So Far I can get all of the duplicates to be flagged using:

 

 

Column = 
Var Equipment = [Fault Equipment]
Return Calculate(If(COUNTROWS(Sheet1)>1,"Yes","No"),All(Sheet1),Sheet1[Fault Equipment]=Equipment)

 

 

My challenge comes in where I try to first integrate the date into this, i have tried using as the second filter argument of 

 

 

Sheet1[FaultDate]=Calendar(Earlier(Sheet1[FaultDate].[Date]),Earlier(Sheet1[FaultDate].[Date]))

 

 

I also tried using the DatesBetween function, but just can not seem to get it to even compile. Having tried using the DateAdd function as well as manually decomposing and re-composing the date values

 

 

DatesBetween((Sheet1[FaultDate]),DateAdd(Earlier(Sheet1[FaultDate]),-30,DAY),Earlier(Sheet1[FaultDate])))


DatesBetween((Sheet1[FaultDate]),Date(Year(Earlier(Sheet1[FaultDate])),Month(Earlier(Sheet1[FaultDate]))-1,Day(Earlier(Sheet1[FaultDate]))),Earlier(Sheet1[FaultDate])))

 

 

FaultRefFaultDateFault EquipmentRepeatRepeat Date
12021/02/06ANo-
22021/02/17BNo-
32021/02/26CNo-
42021/02/27AYes2021/02/06
52021/03/03DNo-
62021/03/08PNo-
72021/03/12DYes2021/03/03
82021/03/24CYes2021/02/26
92021/04/06ANo-
102021/04/10ENo-

I attached an example table to show what I would want the output to be in the last two columns

 Take note that Line 1 and 3 should not be flagged as that would be the first entries. Also Line 9 is not flagged as it is more that 30 days since the previous entry.

 

Any hints/guidance on where I am going wrong would be highly appreciated.

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

Can you try this column please 

ColumnX = 
Var Equipment = Sheet1[Fault Equipment]
VAR _fDate = Sheet1[FaultDate]
VAR _dateOfDup = CALCULATE(MAX(Sheet1[FaultDate]), FILTER(Sheet1, Sheet1[Fault Equipment] = Equipment && Sheet1[FaultDate] < _fDate))

RETURN 
IF(DATEDIFF(_dateOfDup, _fDate, DAY) < 30, _dateOfDup)

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Have you tried @HotChilli 's formula? It should work for Repeat Date column. For Repeat Flag column, I modify it into below one

Flag = 
Var Equipment = Sheet1[Fault Equipment]
VAR _fDate = Sheet1[FaultDate]
VAR _dateOfDup = CALCULATE(MAX(Sheet1[FaultDate]), FILTER(Sheet1, Sheet1[Fault Equipment] = Equipment && Sheet1[FaultDate] < _fDate))
VAR _dateDiff = DATEDIFF(_dateOfDup, _fDate, DAY)
RETURN 
IF(_dateDiff < 30 && NOT(ISBLANK(_dateDiff)), "Yes", "No")

21102603.jpg

 

Best Regards,
Community Support Team _ Jing

HotChilli
Super User
Super User

Can you try this column please 

ColumnX = 
Var Equipment = Sheet1[Fault Equipment]
VAR _fDate = Sheet1[FaultDate]
VAR _dateOfDup = CALCULATE(MAX(Sheet1[FaultDate]), FILTER(Sheet1, Sheet1[Fault Equipment] = Equipment && Sheet1[FaultDate] < _fDate))

RETURN 
IF(DATEDIFF(_dateOfDup, _fDate, DAY) < 30, _dateOfDup)
Anonymous
Not applicable

Hi Thanks, 

This works perfectly!!! 

Just for my own information, in the Calculate function, in the filter, which one of the arguments is referring to the "current" row for the calculation? Would it be the Sheet1[Fault Equipment] or the variable that was declared?

 

Then as an added thought, would it be possible to do this in a Measure instead of a calculated column?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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