Forum Discussion
mblydt-hansen
8 years agoFrequent Visitor
Date difference between values in same column
Hi everyone! I'm still learning DAX and I was wondering if the collective minds of this forum could help me out with coding a custom column that I've been having difficulty with. I feel like my i...
- 8 years ago
You could use this calculated column
Column = VAR temp = TOPN ( 1, FILTER ( Table1, Table1[Patient ID] = EARLIER ( Table1[Patient ID] ) && Table1[Date of Visit] < EARLIER ( Table1[Date of Visit] ) ), [Date of Visit], DESC ) RETURN DATEDIFF ( MINX ( temp, [Date of Visit] ), Table1[Date of Visit], DAY )
Zubair_Muhammad
8 years agoCommunity Champion
You could use this calculated column
Column =
VAR temp =
TOPN (
1,
FILTER (
Table1,
Table1[Patient ID] = EARLIER ( Table1[Patient ID] )
&& Table1[Date of Visit] < EARLIER ( Table1[Date of Visit] )
),
[Date of Visit], DESC
)
RETURN
DATEDIFF ( MINX ( temp, [Date of Visit] ), Table1[Date of Visit], DAY )Anonymous
4 years agoNot applicable
Hi there,
Do you have any advise for my issue?
This code works to get the same output for my dataset, however I need the 'number of days since last visit' to become 'days until next visit'. Essentially meaning all values move up by 1 row. So in the example above the result '5' moves from row 3 to row 2. This is because I have a further column to consider of 'treatment type' per patient ID and need to be able to graphically present the mean time until next visit per treatment type, so I need the 'days until next visit' result in the same row as 'treatment type.'