Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
I need to calculate the difference between dates in the same column. For example:
| Field | Input | Date |
| P1 | Enzow | 2024/01/24 |
| P1 | Plut | 2024/02/25 |
| P1 | Plut | 2024/02/19 |
| P1 | Plut | 2024/02/10 |
| P1 | Enzow | 2024/01/20 |
| P2 | Plut | 2024/02/10 |
| P2 | Enzow | 2024/01/20 |
| P2 | Enzow | 2024/01/12 |
| P2 | Enzow | 2024/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:
| Field | Input | Date | Difference |
| P1 | Enzow | 2024/01/24 | 4 |
| P1 | Plut | 2024/02/25 | 6 |
| P1 | Plut | 2024/02/19 | 9 |
| P1 | Plut | 2024/02/10 | |
| P1 | Enzow | 2024/01/20 | |
| P2 | Plut | 2024/02/10 | |
| P2 | Enzow | 2024/01/20 | 8 |
| P2 | Enzow | 2024/01/12 | 2 |
| P2 | Enzow | 2024/01/10 |
If there is no previous date, there should not be a value.
Solved! Go to Solution.
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
)
Hope this will help you.
Thank you.
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
)
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.
Hope this will help you.
Thank you.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 43 | |
| 39 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 68 | |
| 63 | |
| 31 | |
| 30 | |
| 23 |