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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
patrickoleary85
Frequent Visitor

DAX for datediff of values different rows

Hi,

I am trying to use datediff in a column to gather the number of days between two events. I'm unable to produce the data. I think it something small I am missing, but I cannot figure it out. 

 

Here is a visual of my data. On the lefthand side, it is displaying each user, then a created receipts date and a created results date. 

 

For the item below, the Results date and Receipts date are two different events for the same user. I am trying to calculate the amount of time from Receipt to Results. I can provide a bit more information but hopefully this is enough to gather needed support. Thank you in advance

 

patrickoleary85_1-1711030015306.png

 

 

1 ACCEPTED SOLUTION

Hi @patrickoleary85 , 

Based on your response, I understand that you want to see the date difference for all users. So, I made a modification to the test table Table as shown in the image. New column Diff between Receipt and Results and input:

 

Diff between Receipt and Results = 
   VAR A = MAXX(FILTER('Table',EARLIER('Table'[User])  = 'Table'[User]),'Table'[Created].[Day])
   VAR B = MINX(FILTER('Table',EARLIER('Table'[User])  = 'Table'[User]),'Table'[Created].[Day])
   RETURN
   IF('Table'[Document Type]="Receipt",B-A,A-B)

 

vyanimeimsft_0-1711441311522.png

You can modify the DAX code according to your needs. Hope it works for you!

 

Best Regards,

Caroline Mei

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

6 REPLIES 6
v-yanimei-msft
Community Support
Community Support

Hi all , 

Thanks for the reply from @Joe_Barry ,please allow me to provide anther insight:

Based on the information you show, I will give you the following steps to solve the problem.

1.The test table Table.

vyanimeimsft_0-1711098676160.png

2.New Measure. As an example, if you want the date difference between the Receipts date and Results date when User is AA, you can use the following DAX. LOOKUPVALUE function (DAX) - DAX | Microsoft Learn

 

AA's DateDiff = 
//Find the created date of document that User is AA and Document type is Receipt.
VAR StartDate = LOOKUPVALUE('Table'[Created],'Table'[Document Type],"Receipt",'Table'[User],"AA")
//Find the created date of document that User is AA and Document type is Results.
VAR EndDate = LOOKUPVALUE('Table'[Created],'Table'[Document Type],"Results",'Table'[User],"AA")
RETURN DATEDIFF(StartDate,EndDate,DAY)

 

3.The outcome is in the following picture. AA's DateDiff is added to Card’s Fields.

vyanimeimsft_1-1711098731900.png

If you still have trouble in it, you may need to answer some questions.

1. In what form do you want to display the results you want? Want to select users with a slicer? Are the results displayed on cards or in a table? If so, what are the display requirements?

2.Do you have only two document types (Receipt and Results) for each user? If there are other types, how do you want to do it?

 

 

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

Hi, I believe this would work but I was blocked while creating the VAR StartDate. The issue is that I need to gather data for all Users, and the logic you gave only allows me to look at a single user. Is there a modification to this logic that would allow me to look at all users?

Hi @patrickoleary85 , 

Based on your response, I understand that you want to see the date difference for all users. So, I made a modification to the test table Table as shown in the image. New column Diff between Receipt and Results and input:

 

Diff between Receipt and Results = 
   VAR A = MAXX(FILTER('Table',EARLIER('Table'[User])  = 'Table'[User]),'Table'[Created].[Day])
   VAR B = MINX(FILTER('Table',EARLIER('Table'[User])  = 'Table'[User]),'Table'[Created].[Day])
   RETURN
   IF('Table'[Document Type]="Receipt",B-A,A-B)

 

vyanimeimsft_0-1711441311522.png

You can modify the DAX code according to your needs. Hope it works for you!

 

Best Regards,

Caroline Mei

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

This resolved it, thank you very much!

Joe_Barry
Super User
Super User

Hi @patrickoleary85 

 

Do the Results date and Receipts date appear in the same line in the table? Create a calculated columns and add the measure below, relacing the Table with your table name. I hope this helps!

Diff = DATEDIFF(Table[Results date], Table[Receipts date], DAY)

 

If you found my answer helpful and it solved your issue, please accept as solution




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

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn
Let's connect on LinkedIn


Hi and thank you, Joe! This wasn't successful for me. The items are not on the same line/row. So the two types of Document Type look at the same Created column

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.