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

Calculate number of days between 2 dates in different rows

Hello community members, 

 

I have the following question: 

 

A client can have a type of therapy(Product) more than once. Now I need to know the time (in days) between the Enddate of the 1st therapy and the Startdate of the next therapy from the same sort. (e.g. the time between Wmo1A 1-5-2021, Enddate first therapy, and 1-6-2021, startdate second therapy). Can someone help me with the correct formula for the calculated column? 

 

Hope to hear soon from you! 

 

Best regards, Sander

 

ClientIndicationNumberProductStartdateEnddate
Sander1984df1sda651fWmo1A1-1-20211-5-2021
Sander198484f6as4f65Jeugd2C1-1-20211-12-2021
Sander1984564g1f32sdgWmo1A1-6-20211-11-2021
Sander1984fadas5f465dJeugd2C1-2-2022 
Sander1984f465dsaf1d3Wmo1A1-4-2022 
Piet191098df7a98dWmo1A1-1-20211-10-2021
Piet191034kl34jkld0Wmo1A13-4-2022 

 

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 

Please add the following column

Days = 

var __client = [Client]
var __prod = [Product]
var __startdate = [Startdate]
var __t = 
    FILTER(
        Table11,
        Table11[Client] = __client && Table11[Product] = __prod
    )
var __lastdate = maxx( FILTER( __t,Table11[Enddate] < __startdate ) , Table11[Enddate])
return
IF(
    __lastdate <> BLANK(), INT([Startdate] - __lastdate)
)

Fowmy_0-1622467453167.png

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

4 REPLIES 4
Fowmy
Super User
Super User

@Anonymous 

Please add the following column

Days = 

var __client = [Client]
var __prod = [Product]
var __startdate = [Startdate]
var __t = 
    FILTER(
        Table11,
        Table11[Client] = __client && Table11[Product] = __prod
    )
var __lastdate = maxx( FILTER( __t,Table11[Enddate] < __startdate ) , Table11[Enddate])
return
IF(
    __lastdate <> BLANK(), INT([Startdate] - __lastdate)
)

Fowmy_0-1622467453167.png

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

@Fowmy, thank you! This works perfect! 

amitchandak
Super User
Super User

@Anonymous , Try a new column like

 

new column =
var _client = [client]
var _end = [Enddate]

return
datediff([Enddate] ,minx(filter(table, [client] =_client && [Start Date] > _end), [Start Date]) , day)



or

new column =
var _client = [client]
var _st = [Start Date]
return
datediff([Enddate] ,maxx(filter(table, [client] =_client && [Enddate] < _st), [Enddate]) , day)

Anonymous
Not applicable

@amitchandak Almost perfect, I only miss the combination with the product...

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.