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
redbrumby
Regular Visitor

Calculate date difference between first and last date by ID

Hi, 

 

I have a dataset (much larger and not filtered however) which looks like the following: 

 

Event DateID
26/07/20167076341
26/07/20167055292
2/08/20167055292
20/09/20167076341
25/10/20167076341
22/11/20167076341
16/12/20167076341
23/12/20167311257


I need to calculate the days between the first and last date for each unique ID. The formula might also need to check if an ID has two dates or not. 

 

I've explored a few ideas but am not that confident in DAX.

 

Thanks in advance for your help,

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

HI @redbrumby

 

This calculated table may give you want you want.  I have attached a simple PBIX file

 

Table = 
    SUMMARIZECOLUMNS(
        'Table1'[ID] ,
        "Min Date" , MIN('Table1'[Event Date]) ,
        "Max Date" , MAX('Table1'[Event Date]) ,
        "Date Diff" , DATEDIFF( MIN('Table1'[Event Date]), MAX('Table1'[Event Date]),DAY)
    )

image.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

 

i dragged ID to the rows labels of the Table visual and wrote the following measure

 

Diff = 1*(MAX(Data[Event Date])-MIN(Data[Event Date]))

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Phil_Seamark
Employee
Employee

HI @redbrumby

 

This calculated table may give you want you want.  I have attached a simple PBIX file

 

Table = 
    SUMMARIZECOLUMNS(
        'Table1'[ID] ,
        "Min Date" , MIN('Table1'[Event Date]) ,
        "Max Date" , MAX('Table1'[Event Date]) ,
        "Date Diff" , DATEDIFF( MIN('Table1'[Event Date]), MAX('Table1'[Event Date]),DAY)
    )

image.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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.