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
Kish1999
Helper II
Helper II

Get Current and previous date

Helo All,

 

I Have a requirement where we have to check if a particular date has been changed and if it has been changed then find by how many days it has been changed. The date can be pushed back or borught forward.

The modified date can changed based on some other factors other than date change. Below is a sample data and expected output:

ProjectDate1Modified date
   
A01-05-202301-05-2023
A07-05-202303-05-2023
A12-06-202306-05-2023
A12-06-202310-05-2023
A12-06-202312-05-2023
B10-05-202302-05-2023
B21-04-202304-05-2023
B21-04-202306-05-2023

 

Output   
ProjectCurrDatePrevDateVar
A12-06-202307-05-202336
B21-04-202310-05-2023-20

 

I have written two measures to get the data, but it seems to be giving me the wrong data and i somewhat know why, can someone please help me with this.

CurrDate =
calculate(max(Table[Date1]), all(Table[Date1]), Table[ModifiedDate] = Max(Table[ModifiedDate]))
 
PrevDate = 
Var MaxDate = Calculate(max(Table[Date1]), all(Table[Date1]))
Var MaxModDate = Calculate(max(ModifiedDate), all(Table[ModifiedDate]))
Var PrevModDate = Calculate(Max(Table[ModifiedDate]), Table[ModifiedDate]<MaxModDate)
Var PrevDate = Calculate(Max(Table[Date1]),  Table[ModifiedDate] = PrevModDate)

Return PrevDate
 
 Reagrds
1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Kish1999 ,

 

Please try:

CurrDate = 
var _a = MAX('Table'[Modified date])
return CALCULATE(MAX('Table'[Date1]),FILTER('Table',[Modified date]=_a))

PrevDate = 
var _a = [CurrDate]
var _b = CALCULATE(MIN('Table'[Modified date]),FILTER('Table',[Date1]=_a))
var _c = CALCULATE(MAX('Table'[Modified date]),FILTER('Table',[Modified date]<_b))
return CALCULATE(MAX('Table'[Date1]),FILTER('Table',[Modified date]=_c))

Var = DATEDIFF([PrevDate],[CurrDate],DAY)

Output:

vjianbolimsft_0-1685931659088.png

Best Regards,

Jianbo Li

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

1 REPLY 1
v-jianboli-msft
Community Support
Community Support

Hi @Kish1999 ,

 

Please try:

CurrDate = 
var _a = MAX('Table'[Modified date])
return CALCULATE(MAX('Table'[Date1]),FILTER('Table',[Modified date]=_a))

PrevDate = 
var _a = [CurrDate]
var _b = CALCULATE(MIN('Table'[Modified date]),FILTER('Table',[Date1]=_a))
var _c = CALCULATE(MAX('Table'[Modified date]),FILTER('Table',[Modified date]<_b))
return CALCULATE(MAX('Table'[Date1]),FILTER('Table',[Modified date]=_c))

Var = DATEDIFF([PrevDate],[CurrDate],DAY)

Output:

vjianbolimsft_0-1685931659088.png

Best Regards,

Jianbo Li

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

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