Forum Discussion
Calculating days between dates in same column
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 ) + 0
Otherwise, remove this line:
&& 'Table'[ClientName] = EARLIER ( 'Table'[ClientName] )
- Nepal1012 years agoHelper 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.
- danextian2 years agoSuper 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.
- Nepal1012 years agoHelper III
Hello danextian
Thank you so much for your insight.
I have one more question is there a way to coun the days when the sales person is assigned instead of showing 0daysas the sales person was assigned on that paticular day I need to count that day as one to get the correct value.