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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
AlfredASC
Frequent Visitor

Subtracting from previous cell in Another column

I am trying to get the delta between when a user's certificate expires and when they purchased the renewal.

I have one column of puchase dates, and one column of expiration dates.
I need to subtract the current puchase date from the PREVIOUS expiration date.

I've tried multiple combinations with the EARLIER funtion with no success.
Below is how this would be completed in excel.

Any help someone can provide would be appreciated!

 

Adjacent Cells.JPG

 

1 ACCEPTED SOLUTION

@Greg_Deckler 
Didn't quite follow that. I ended up finding a solution though.

I set up two columns, one was the sequence of the occourence:

Sequence =
COUNTROWS(
FILTER(
CALCULATETABLE(
'table name',
ALLEXCEPT('table name','table name'[Unique User])),
'table name'[Purchase Date]<EARLIER('table name'[Purchase Date]) || ('table name'[Purchase Date]=EARLIER('table name'[Purchase Date]) && 'table name'[Purchase Time] <= EARLIER('table name'[Purchase Time]))))

Then I set up sequence -1.

Using these I was able to run a "Previous Expiration" LOOKUPVALUE for the [Expiration Date], when  [Unique User | sequce] = [Unique User | sequence-1]. That look up table gave me all of the previous expirations dates that I was able to build tables and my [Purchase Date] - [Previous Expiration] measure from.

View solution in original post

4 REPLIES 4
v-yuta-msft
Community Support
Community Support

@AlfredASC ,

 

Click Editor Query-> Transform-> Add an Index, then create a calculate column using DAX below:

Days Early or Late = 
VAR Current_Index = 'Table'[Index]
VAR Current_Purchase_Date = 'Table'[Purchase Date]
VAR Previous_Expiration_Date = CALCULATE(MAX('Table'[Expiration Date]), FILTER('Table', 'Table'[Index] = Current_Index - 1))
RETURN
DATEDIFF(Previous_Expiration_Date, Current_Purchase_Date, DAY)

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

Thanks @v-yuta-msft 
For some reason that solution just subtracted all of my expiration dates by 1. Maybe it's because of the way the data tables were built. The purchases are per customer. I'm guessing, since the sequence of purchases for customer A can fall between the purchases for customers B and C, the index function would work for my specific case.

Greg_Deckler
Community Champion
Community Champion

Should be the MAXX of Purchase Date for FILTER of the table where Purchase Date < EARLIER Purchase Date. Then you could do a MAXX for Expiration Date for the FILTER of that table filtered down to a Purchase Date equal to the previous value.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 
Didn't quite follow that. I ended up finding a solution though.

I set up two columns, one was the sequence of the occourence:

Sequence =
COUNTROWS(
FILTER(
CALCULATETABLE(
'table name',
ALLEXCEPT('table name','table name'[Unique User])),
'table name'[Purchase Date]<EARLIER('table name'[Purchase Date]) || ('table name'[Purchase Date]=EARLIER('table name'[Purchase Date]) && 'table name'[Purchase Time] <= EARLIER('table name'[Purchase Time]))))

Then I set up sequence -1.

Using these I was able to run a "Previous Expiration" LOOKUPVALUE for the [Expiration Date], when  [Unique User | sequce] = [Unique User | sequence-1]. That look up table gave me all of the previous expirations dates that I was able to build tables and my [Purchase Date] - [Previous Expiration] measure from.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.