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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jppuam
Helper V
Helper V

Count different days from date on the record before

Hello, i'm trying to count the days between the record date and the previous record (as i show in the example)Untitled.png

For each Numbef, i've a appointment date, and i've to calculate the diference between the record date, and the previous record.

For example, in Numbef = 3, 146 days (on one record) that is the diference between 18 July and 22 Fev.

Can you help me with this ?

 

thanks,

jppuam

1 ACCEPTED SOLUTION

Hi @jppuam ,

 

 

1.jpg

 

 

Click on Calculated Column

 

Difference in Days =
var _a = CALCULATE(MAX('Table'[DataFimServico]),Filter('Table','Table'[NumBeneficiario]=EARLIER('Table'[NumBeneficiario]) && 'Table'[DataFimServico] < EARLIER('Table'[DataFimServico])))

var _b = DATEDIFF(_a,'Table'[DataFimServico],DAY)
RETURN
IF (_b =BLANK(),0,_b)

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@jppuam ,

As a new colum

Diff COlumn = datediff(maxx(filter(Table,Table[Date]<earlier(Table[Date]) && Table[Numberf]= earlier(Table[Numberf]) ),Table[Date]) ,Table[Date],Day)

 

As a measure

example with date table

Last Day Non Continous = CALCULATE(sum('order'[Qty]),filter(all('Date'),'Date'[Date] =MAXX(FILTER(all('Date'),'Date'[Date]<max('Date'[Date])),'order'['Date'])))
Day behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Day))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...


Appreciate your Kudos.

 

 

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

Hi amitchandak,

thanks for the response, but i quite not compreend.

can i sent by email you a test file for you to exemplified ?

 

NumBeneficiarioDataFimServicoNumPrestadorDias entre AtosMedicos
102/01/20193748980
223/02/20193748980
219/12/2019369757299
220/12/20193748981
322/02/20193749140
318/07/2019364971146
322/11/2019374914127
412/07/20193733760
419/07/20193749147
420/08/201937337632
424/09/201937337635
416/10/201935615722
410/12/201937337655
522/02/20193749140
508/04/201936719745
518/07/2019364971101
611/03/20193723480
627/05/201937234877
616/07/201937234850
626/07/201937234810
630/07/20193723484
602/10/201937234864
603/12/201937234862
618/12/201937234815
704/03/20193723480
713/05/201935501870
708/08/201935501887

thanks very much,

jppuam

Hi @jppuam ,

 

 

1.jpg

 

 

Click on Calculated Column

 

Difference in Days =
var _a = CALCULATE(MAX('Table'[DataFimServico]),Filter('Table','Table'[NumBeneficiario]=EARLIER('Table'[NumBeneficiario]) && 'Table'[DataFimServico] < EARLIER('Table'[DataFimServico])))

var _b = DATEDIFF(_a,'Table'[DataFimServico],DAY)
RETURN
IF (_b =BLANK(),0,_b)

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Thank you harshnathani it works perfect.

i've another question regarding this issue, but i'll create another post.

 

regards,

jppuam

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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