Forum Discussion
Calculating days between dates in same column
Hello Everyone,
I have a question regarding how to calculate the column or Measure that gives me days between dates
| Date | ClientName | salesperson | Days Between | Running total days or sum days |
| 10/26/2023 | 123 | null | 0 (because the salesperson is not assigned) | 0 |
| 10/27/2023 | 123 | A | 1 | 1 |
| 10/30/2023 | 123 | A | 3 | 4 |
| 11/6/2023 | 123 | A | 7 | 11 |
| 11/7/2023 | 1213 | a | 1 | 12 |
from the same column and on top of that I need to have the sum of days for each row.
Is there a way to calculate the Total days or sum days and days between
I hope someone can help me get this result.
Thank you in advance
8 Replies
- danextianSuper User
Hi Nepal101 ,
Assuming that the days difference is to be calculated by client name:
Days Diff = VAR __PREV = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', 'Table'[Date] < EARLIER ( 'Table'[Date] ) && 'Table'[ClientName] = EARLIER ( 'Table'[ClientName] ) ) ) RETURN DATEDIFF ( __PREV, 'Table'[Date], DAY ) + 0Otherwise, remove this line:
&& 'Table'[ClientName] = EARLIER ( 'Table'[ClientName] )- Nepal101Helper III
I tried to use the column as you have stated. I think there is a logic missing regarding the salesperson so if the sales person is not assigned then the day should not be count. Can we create that column accordingly.
- danextianSuper User
Hi Nepal101
Use this instead:
Days Diff = VAR __PREV = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( 'Table', 'Table'[Date] < EARLIER ( 'Table'[Date] ) && 'Table'[ClientName] = EARLIER ( 'Table'[ClientName] ) && 'Table'[salesperson] <> "null" ) ) RETURN DATEDIFF ( __PREV, 'Table'[Date], DAY ) + 0As to the running total, you can either use a calc column or a measure but calc column is not to be aggregated as it will show incorrect sub or grand total. Please see attached pbix for the details.