I have the departure date and arrival date for a train in my dataset.
I want to have a new column in my analysis that will have the number of days since the last departure
I need the departure date from the previous run of the train and the arrival date from the current run. I am trying to find the number of days it took to arrive since it departed. I tried to use the LAG function to get the departure date from the previous run but got the error.
LAG is an aggregated function, while datediff is not. And I don’t think you can mix them. That’s probably what your problem is. I would recommend bringing the previous departure date as a separate column, And then calculate it. KISS (Keep it simple and Stupid)
You need to ensure that both inputs to the dateDiff function are coming from either aggregated or non-aggregated fields (in your example it would need to be aggregated). I’ve used the sample data that you’ve provided and built a quick sample solution within the newly launched QuickSight Arena. For sake of readability, I’ve separated the calculated field into 3 fields. Using QuickSight Arena, you can dive deep into it my solution directly within the community. Date diff to previous row
Combined, the calculation for the No of days since previous departure field would look like this: