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
ToddMate
Helper II
Helper II

Calculate Difference Between Dates in Same Column

Hi All,

 

I need help in determining the difference between two dates that reside in the same column on seperate rows in the same table. I have a Sales date on one row and a Connected date on another row, the table is called TransactionsFACT.

 

In the example i would expect to see 5 days as the answer. (15/04/2019 - 10/04/2019)

 

These share a unique combination of Account Number and Service Number as per the screenshot. (excel screenshot)

 

The bigger picture here is that i would like to apply this across all entries in the table and store this in a calculated column for use in further analysis.

 

Is anyone able to assist me.

 

Screen Shot 2019-04-28 at 8.40.10 pm.png

1 ACCEPTED SOLUTION

Hi,

This calculated column formula works

=if(Table1[transaction Type]="Connected",Table1[Date of Transaction]-CALCULATE(MAX(Table1[Date of Transaction]),FILTER(Table1,Table1[Account Number]=EARLIER(Table1[Account Number])&&Table1[Service Number]=EARLIER(Table1[Service Number])&&Table1[transaction Type]="Sale")),BLANK())

Hope this helps.

Untitled.png


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

View solution in original post

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Against one sale date would there be only one connected date for that Account and Service Number?  If not, then which dates should be subtracted?  Please show thr expected result in Column E.


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

@Ashish_Mathur Yes that is correct, there can ever only be one sales date and one connected date per combination of Account & Service. (In this case Account Number 1234 and Service Number 555)

 

Column E, Row 4 would simply contain '5' representing the 5 days between 10/04/2019 & 15/04/2019

 

Capture4.JPG

Hi,

This calculated column formula works

=if(Table1[transaction Type]="Connected",Table1[Date of Transaction]-CALCULATE(MAX(Table1[Date of Transaction]),FILTER(Table1,Table1[Account Number]=EARLIER(Table1[Account Number])&&Table1[Service Number]=EARLIER(Table1[Service Number])&&Table1[transaction Type]="Sale")),BLANK())

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@ToddMate try this measure

 

# Days = 
VAR __salesDate = CALCULATE( MAX( Table1[TransactionDate] ), 
ALLEXCEPT( Table1, Table1[AccountNumber], Table1[TransactionType] ),
Table1[TransactionType] = "Sale" ) VAR __connectedDate = CALCULATE( MAX( Table1[TransactionDate] ),
ALLEXCEPT( Table1, Table1[AccountNumber], Table1[TransactionType] ),
Table1[TransactionType] = "Connected" ) RETURN DATEDIFF( __salesDate, __connectedDate, DAY )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.