title: Application Insights query to get time between 2 custom events
body: <p>I am trying to write a query that will get me the average time between 2 custom events, sorted by user session. I have added custom tracking events throughout this application and I want to query the time it takes the user from 'Setup' event to 'Process' event.</p>
  
  <pre><code>let allEvents=customEvents
  | where timestamp between (datetime(2019-09-25T15:57:18.327Z)..datetime(2019-09-25T16:57:18.327Z))
  | extend SourceType = 5;
  let allPageViews=pageViews
  | take 0;
  let all = allEvents
  | union allPageViews;
  let step1 = materialize(all
  | where name == "Setup" and SourceType == 5
  | summarize arg_min(timestamp, *) by user_Id
  | project user_Id, step1_time = timestamp);
  let step2 = materialize(step1
  | join
      hint.strategy=broadcast                      (all
      | where name == "Process" and SourceType == 5
      | project user_Id, step2_time=timestamp
  )
  on user_Id
  | where step1_time &lt; step2_time
  | summarize arg_min(step2_time, *) by user_Id
  | project user_Id, step1_time,step2_time);
  let 1Id=step1_time;
  let 2Id=step2_time;
  1Id
  | union 2Id
  | summarize AverageTimeBetween=avg(step2_time - step1_time)
  | project AverageTimeBetween
  </code></pre>
  
  <p>When I run this query it produces this error message:</p>
  
  <p>'' operator: Failed to resolve table or column or scalar expression named 'step1_time'</p>
  
  <p>I am relatively new to writing queries with AI and have not found many resources to assist with this problem. Thank you in advance for your help!</p>