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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
jobf
Helper II
Helper II

Multiple differences between values ​​in the same column

I need to calculate the difference between dates in the same column. For example:

FieldInputDate
P1Enzow2024/01/24
P1Plut2024/02/25
P1Plut2024/02/19
P1Plut2024/02/10
P1Enzow2024/01/20
P2Plut2024/02/10
P2Enzow2024/01/20
P2Enzow2024/01/12
P2Enzow2024/01/10


I need to create a column that calculates the difference between the current date and the previous date in days, based on the Field and Input column. The final table would look something like this:

FieldInputDate Difference
P1Enzow2024/01/24 4
P1Plut2024/02/25 6
P1Plut2024/02/19 9
P1Plut2024/02/10 
P1Enzow2024/01/20 
P2Plut2024/02/10 
P2Enzow2024/01/20 8
P2Enzow2024/01/12 2
P2Enzow2024/01/10 


If there is no previous date, there should not be a value.

1 ACCEPTED SOLUTION
Irwan
Super User
Super User

hello @jobf 

 

please check if this accomodate your need.

Difference =
var _MinDate = MINX(FILTER('Table','Table'[Field]=EARLIER('Table'[Field])&&'Table'[Input]=EARLIER('Table'[Input])),'Table'[Date])
var _PreviousDate =
CALCULATE(
    MAX('Table'[Date]),
    ALL('Table'),
    OFFSET(-1,ORDERBY('Table'[Date]),PARTITIONBY('Table'[Field],'Table'[Input]))
)
Return
IF(
    'Table'[Date]=_MinDate,
    BLANK(),
    'Table'[Date]-_PreviousDate
)

Irwan_0-1721260990209.png

 

Hope this will help you.

Thank you.

View solution in original post

3 REPLIES 3
Irwan
Super User
Super User

hello @jobf 

 

please check if this accomodate your need.

Difference =
var _MinDate = MINX(FILTER('Table','Table'[Field]=EARLIER('Table'[Field])&&'Table'[Input]=EARLIER('Table'[Input])),'Table'[Date])
var _PreviousDate =
CALCULATE(
    MAX('Table'[Date]),
    ALL('Table'),
    OFFSET(-1,ORDERBY('Table'[Date]),PARTITIONBY('Table'[Field],'Table'[Input]))
)
Return
IF(
    'Table'[Date]=_MinDate,
    BLANK(),
    'Table'[Date]-_PreviousDate
)

Irwan_0-1721260990209.png

 

Hope this will help you.

Thank you.

Is there a way to put a zero in place of this empty space in earliest dates?

hello @jobf 

 

use 0 instead of BLANK for true value in if statement.

Irwan_0-1721328888991.png

 

Hope this will help you.

Thank you.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors