Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
I need to create a column in a table that allows calculating the difference between dates in the same column according to some conditions. For example:
Field | Application | Date |
P1 | 1st application | 01/02/2024 |
P1 | 1st application | 01/04/2024 |
P1 | 2nd application | 01/10/2024 |
P1 | 3rd application | 01/21/2024 |
P2 | 1st application | 01/03/2024 |
P2 | 1st application | 01/05/2024 |
P2 | 2nd application | 01/13/2024 |
P2 | 3rd application | 01/25/2024 |
P2 | 3rd application | 01/24/2024 |
P2 | 3rd application | 01/27/2024 |
P3 | 1st application | 01/07/2024 |
P3 | 2nd application | 01/15/2024 |
P3 | 2nd application | 01/14/2024 |
P3 | 3rd application | 01/28/2024 |
I need a column that calculates the difference between the earsliest dates in the set of field applications with close values. For example, in field P1, I need to take the earliest date of the 2nd application and the earliest date of the 1st application and, subsequently, calculate the difference between them. I need this on all fields. The final table would look like this:
Field | Application | Date | Difference |
P1 | 1st application | 01/02/2024 | |
P1 | 1st application | 01/04/2024 | |
P1 | 2nd application | 01/10/2024 | 8 |
P1 | 3rd application | 01/21/2024 | 11 |
P2 | 1st application | 01/03/2024 | |
P2 | 1st application | 01/05/2024 | |
P2 | 2nd application | 01/13/2024 | 10 |
P2 | 3rd application | 01/25/2024 | 11 |
P2 | 3rd application | 01/24/2024 | 11 |
P2 | 3rd application | 01/27/2024 | 11 |
P3 | 1st application | 01/07/2024 | |
P3 | 2nd application | 01/15/2024 | 7 |
P3 | 2nd application | 01/14/2024 | 7 |
P3 | 3rd application | 01/28/2024 | 14 |
Solved! Go to Solution.
Hello @jobf
please check if this accomodate your need.
This is my understanding from your explaination.
- you dont need between any 1st application difference (zero difference)
- in same field, you want to get a difference between the earliest 2nd application and the earliest 1st application. and the earliest 3rd application and the earliest 2nd application.
Create a calculated column with following DAX
Hi @jobf ,
Thanks for the reply from @Irwan and @foodd , please allow me to provide another insight:
1. Create a calculated column to get the earliest date.
EarliestDate =
CALCULATE(
MIN('Table'[Date]),
ALLEXCEPT('Table', 'Table'[Field], 'Table'[Application])
)
2. Create a calculated column to convert the Application column to a number.
NumApplication =
VALUE(LEFT('Table'[Application], 1))
3. Create a calculated column to get the difference in dates.
Difference =
VAR CurrentApplication = 'Table'[NumApplication]
VAR CurrentField = 'Table'[Field]
VAR CurrentDate = 'Table'[Date]
VAR PreviousApplicationDate =
CALCULATE(
MIN('Table'[EarliestDate]),
FILTER(
'Table',
'Table'[Field] = CurrentField &&
'Table'[NumApplication] = CurrentApplication - 1
)
)
RETURN
IF(
ISBLANK(PreviousApplicationDate),
BLANK(),
DATEDIFF(PreviousApplicationDate, 'Table'[EarliestDate], DAY)
)
4. You can click the small eye next to the field to hide unnecessary columns.
If your Current Period does not refer to this, please clarify in a follow-up reply.
Best Regards,
Clara Gong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @jobf ,
Thanks for the reply from @Irwan and @foodd , please allow me to provide another insight:
1. Create a calculated column to get the earliest date.
EarliestDate =
CALCULATE(
MIN('Table'[Date]),
ALLEXCEPT('Table', 'Table'[Field], 'Table'[Application])
)
2. Create a calculated column to convert the Application column to a number.
NumApplication =
VALUE(LEFT('Table'[Application], 1))
3. Create a calculated column to get the difference in dates.
Difference =
VAR CurrentApplication = 'Table'[NumApplication]
VAR CurrentField = 'Table'[Field]
VAR CurrentDate = 'Table'[Date]
VAR PreviousApplicationDate =
CALCULATE(
MIN('Table'[EarliestDate]),
FILTER(
'Table',
'Table'[Field] = CurrentField &&
'Table'[NumApplication] = CurrentApplication - 1
)
)
RETURN
IF(
ISBLANK(PreviousApplicationDate),
BLANK(),
DATEDIFF(PreviousApplicationDate, 'Table'[EarliestDate], DAY)
)
4. You can click the small eye next to the field to hide unnecessary columns.
If your Current Period does not refer to this, please clarify in a follow-up reply.
Best Regards,
Clara Gong
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @jobf
please check if this accomodate your need.
This is my understanding from your explaination.
- you dont need between any 1st application difference (zero difference)
- in same field, you want to get a difference between the earliest 2nd application and the earliest 1st application. and the earliest 3rd application and the earliest 2nd application.
Create a calculated column with following DAX
Check out the April 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
User | Count |
---|---|
20 | |
13 | |
10 | |
10 | |
8 |
User | Count |
---|---|
21 | |
15 | |
9 | |
7 | |
6 |