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
ravi_ch
Helper I
Helper I

How can we calculate dates difference

ravi_ch_0-1647454041579.png

How can we calculate no. of days between two days like
2/12/2020 - 2/20/2020 = 8, 

2/20/2020 - 3/24/2020 = 32

like this

6 REPLIES 6
truptis
Community Champion
Community Champion

Hi @ravi_ch , Please try this:
Step 1: create index column using dax:
Index_column = RANKX(ALL('Tablename'),[Date])

Step 2: using DAX create a new column

PreviousRow = Lookupvalue(tablename[Date], tablename[index_column], tablename[index_column] -1)
Step 3: Create another column for counting the difference

Count = DATEDIFF([Date], [PreviousRow], DAY)

@ravi_ch  -> Mark this as a solution & hit the thumbs up, if it works for you. Thanks.

ravi_ch
Helper I
Helper I

but apply slicer like product mam it won't working.
like for each Product what is difference in days between each sale

 

@ravi_ch 

Pls try this

Measure = 
VAR _last=maxx(FILTER(ALL('Table'),'Table'[Date]<max('Table'[Date])),'Table'[Date])
VAR _DF= DATEDIFF(_last,max('Table'[Date]),DAY)
VAR _last2=maxx(FILTER(ALL('Table'),'Table'[Date]<max('Table'[Date])&&'Table'[Product]=max('Table'[Product])),'Table'[Date])
VAR _DF2=DATEDIFF(_last2,max('Table'[Date]),DAY)
RETURN IF(ISFILTERED('Table'[Product]),_DF2,_DF)

pls see the attachment below.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ryan_mayu
Super User
Super User

@ravi_ch 

you can create a measure

Measure = 
VAR _last=maxx(FILTER(ALL('Table'),'Table'[Date]<max('Table'[Date])),'Table'[Date])
return DATEDIFF(_last,max('Table'[Date]),DAY)

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




truptis
Community Champion
Community Champion

@ravi_ch -> You can also do using DAX.

Step 1: Create index column starting with 1 (Transform data -> Index column -> Start from 1)
Step 2: using DAX create a new column

PreviousRow = Lookupvalue(tablename[Date], tablename[index_column], tablename[index_column] -1)
Step 3: Create another column for counting the difference

Count = DATEDIFF([Date], [PreviousRow], DAY)

@ravi_ch -> Mark this as a solution & hit the thumbs up, if it works for you. Thanks.

truptis
Community Champion
Community Champion

Hi @ravi_ch ,

You can do this is Power Query. 

Step 1- Create an index column.
Step 2 - Add new custom column 

paste this code in it:
= try #"Added Index"{[Index]-1} [Date] otherwise null 

and then click on OK.
this step is going to take the date present in 2nd row to the first row.

 Step 3: Create another column which has your result

Result = DATEDIFF([date], [new column that we created], DAY)
@ravi_ch -> If this works, the  please mark it as a solution.

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.