Forum Discussion
Date difference between values in same column
- 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 )
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_Muhammad8 years agoCommunity Champion
- sv117 years agoHelper I
Hi,
I have followed your footsteps to recreate this DAX script and the following errors are being popped out: (in Red)
Frequency = VAR temp = TOPN(1, FILTER( Freq, Freq[new_AdvisorCRD] = EARLIER(Freq[new_AdvisorCRD]) && Freq[new_Transaction_Date] < EARLIER( Freq[new_Transaction_Date]) ), Freq[new_Transaction_Date], DESC ) return DATEDIFF(MINX(temp, Freq[new_Transaction_Date]), Freq[new_Transaction_Date], DAY)
Do you minf revieing my code?
Thanks for your help
- MAAbdullah_476 years agoHelper V
I have the same problem how you solve it?
- mblydt-hansen8 years agoFrequent Visitor
This is great - I'm getting exactly what I had hoped for. Thank you so much for your help!
- Anonymous7 years agoNot applicable
Hey,
Is there a way to get Date value instead of Date difference as output?
Zubair_Muhammad wrote: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 ) - Anonymous5 years agoNot applicable
Hi,
I have a similar problem. I have 3 columns, one with different products IDs, one with different status and one with dates, which replicate lines adding one day until the product status changes. So I want to calculate the difference between the max date and min date for determined product ID and status.
I applied something similar:
Column =VAR temp =TOPN (1,FILTER (Teste,Teste[Work Item Id] = EARLIER ( Teste[Work Item Id] ) && Teste[State] = EARLIER ( Teste[State] )&& Teste[Date] < EARLIER ( Teste[Date] )),[Date], DESC)RETURNDATEDIFF ( MINX ( temp, [Date] ), Teste[Date], DAY )However, it does not work. Could you please help me?Thank you! - nrungta4 years agoFrequent Visitor
Unlike many accepted solutions in the whole forum.
This actually works.
Thanks, Zubair for sharing your knowledge.
- Anonymous4 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.'
- kriti2020203 years agoNew Member
Hello Zubair,
I have similar requirement just that in first column i have user name instead of user id but the solution is not working for me. 7th and 8th line of formula below is not accepting parameter after EARLIER. Please advise
Table1[Patient ID] = EARLIER ( Table1[Patient ID] ) && Table1[Date of Visit] < EARLIER ( Table1[Date of Visit] )Regards,
Kriti
- Anonymous3 years agoNot applicable
Nearly 5 years later this answer got me out of a jam, thanks so much!