# Create Funnels in New Dashboards Using DQL Queries

**URL:** <https://community.dynatrace.com/t/create-funnels-in-new-dashboards-using-dql-queries/52890>\
**Category:** DQL\
**Tags:** dql, funnel, business-events\
**Created:** [August 11, 2025, 7:55am UTC](https://community.dynatrace.com/t/create-funnels-in-new-dashboards-using-dql-queries/52890 "2025-08-11T07:55:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [August 11, 2025, 7:55am UTC](https://community.dynatrace.com/t/create-funnels-in-new-dashboards-using-dql-queries/52890/1 "2025-08-11T07:55:13Z")

</div>

Hello,

Are there any recommendations on how to have funnel-like visualisations from DQL source? Typically business events now, probably user sessions soon.

I’m looking for some practice close to what funnels in USQL currently are, which means:

- count only consecutive events per correlation id (e.g. session)
- visualization (probably bar chart or pie chart is now the only way)

Bizflow app is not an option in my case for several reasons:

- It is not flexible enough (only allows to select events by event.type without any further conditions)
- It is not possible to pin the funnel on a dashboard

**Update:**  
The best I was able to do at the moment follows:

```markup
data 
  record(timestamp = now()-30m, session="session1", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session1", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-20m, session="session1", `event.provider`="myapp", `event.type`="payment"),
  record(timestamp = now()-30m, session="session2", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session2", `event.provider`="myapp", `event.type`="place_order"),
  // this will not be counted in the funnel
  record(timestamp = now()-30m, session="session_without_first_event", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-25m, session="session_without_first_event", `event.provider`="myapp", `event.type`="payment")   
| filter startsWith(event.provider,"myapp")

// Create boolean fields if step exists in a session
| summarize {
    `add_to_cart` = countIf(event.type=="add_to_cart")>0,
    `place_order` = countIf(event.type=="place_order")>0,
    `payment` = countIf(event.type=="payment")>0
  }, by: { session }
// Summarize events
| summarize 
  funnel = array (
    record(step="Add to cart", count=countIf(`add_to_cart`)),
    record(step="Place order", count=countIf(`add_to_cart` and `place_order`)),
    record(step="Payment", count=countIf(`add_to_cart` and `place_order` and `payment`))
  )
// Expand events into separate records
| expand funnel
| fieldsFlatten funnel
| fieldsRemove funnel

```

[Example](https://wkf10640.apps.dynatrace.com/ui/intent/dynatrace.notebooks/view-query#%7B%22visualization%22%3A%22table%22%2C%22visualizationSettings%22%3A%7B%22table%22%3A%7B%22columnOrder%22%3A%5B%22%5B%5C%22funnel.step%5C%22%5D%22%2C%22%5B%5C%22funnel.count%5C%22%5D%22%5D%7D%7D%2C%22dt.timeframe%22%3A%7B%22from%22%3A%22now()-7d%22%2C%22to%22%3A%22now()%22%7D%2C%22dt.query%22%3A%22data%20%5Cn%20%20record(timestamp%20%3D%20now()-30m%2C%20session%3D%5C%22session1%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22add_to_cart%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-25m%2C%20session%3D%5C%22session1%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22place_order%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-20m%2C%20session%3D%5C%22session1%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22payment%5C%22)%2C%5Cn%20%20record(timestamp%20%3D%20now()-30m%2C%20session%3D%5C%22session2%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22add_to_cart%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-25m%2C%20session%3D%5C%22session2%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22place_order%5C%22)%2C%5Cn%20%20%2F%2F%20this%20will%20not%20be%20counted%20in%20the%20funnel%5Cn%20%20record(timestamp%20%3D%20now()-30m%2C%20session%3D%5C%22session_without_first_event%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22place_order%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-25m%2C%20session%3D%5C%22session_without_first_event%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22payment%5C%22)%20%20%20%5Cn%7C%20filter%20startsWith(event.provider%2C%5C%22myapp%5C%22)%5Cn%5Cn%2F%2F%20Create%20boolean%20fields%20if%20step%20exists%20in%20a%20session%5Cn%7C%20summarize%20%7B%5Cn%20%20%20%20%60add_to_cart%60%20%3D%20countIf(event.type%3D%3D%5C%22add_to_cart%5C%22)%3E0%2C%5Cn%20%20%20%20%60place_order%60%20%3D%20countIf(event.type%3D%3D%5C%22place_order%5C%22)%3E0%2C%5Cn%20%20%20%20%60payment%60%20%3D%20countIf(event.type%3D%3D%5C%22payment%5C%22)%3E0%5Cn%20%20%7D%2C%20by%3A%20%7B%20session%20%7D%5Cn%2F%2F%20Summarize%20events%5Cn%7C%20summarize%20%5Cn%20%20funnel%20%3D%20array%20(%5Cn%20%20%20%20record(step%3D%5C%22Add%20to%20cart%5C%22%2C%20count%3DcountIf(%60add_to_cart%60))%2C%5Cn%20%20%20%20record(step%3D%5C%22Place%20order%5C%22%2C%20count%3DcountIf(%60add_to_cart%60%20and%20%60place_order%60))%2C%5Cn%20%20%20%20record(step%3D%5C%22Payment%5C%22%2C%20count%3DcountIf(%60add_to_cart%60%20and%20%60place_order%60%20and%20%60payment%60))%5Cn%20%20)%5Cn%2F%2F%20Expand%20events%20into%20separate%20records%5Cn%7C%20expand%20funnel%5Cn%7C%20fieldsFlatten%20funnel%5Cn%7C%20fieldsRemove%20funnel%22%2C%22hideInput%22%3Afalse%2C%22sourceApplication%22%3A%22dynatrace.notebooks%22%7D)&nbsp; in the playground environment.

If a specific order of steps is required:

```markup
data 
  record(timestamp = now()-30m, session="session1", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session1", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-20m, session="session1", `event.provider`="myapp", `event.type`="payment"),
  record(timestamp = now()-30m, session="session2", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session2", `event.provider`="myapp", `event.type`="place_order"),
  // this will not be counted in the funnel
  record(timestamp = now()-30m, session="session_without_first_event", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-25m, session="session_without_first_event", `event.provider`="myapp", `event.type`="payment"),
  // session with incorrect order
  record(timestamp = now()-20m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-30m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="payment")

| filter startsWith(event.provider,"myapp")
| sort session, timestamp asc 

// Summarize event by session into an array, so we have steps in an array for each session
| summarize steps = collectArray(event.type), by:{ session }

// Create position of each step
| fieldsAdd 
    `add_to_cart` = arrayIndexOf(steps,"add_to_cart"),
    `place_order` = arrayIndexOf(steps,"place_order"),
    `payment` = arrayIndexOf(steps,"payment")
// Replace -1 with null so we can compare order    
| fieldsAdd     
    `add_to_cart` = if(`add_to_cart`>=0, `add_to_cart`, else: null),
    `place_order` = if(`place_order`>=0, `place_order`, else: null),
    `payment` = if(`payment`>=0, `payment`, else: null)

// Summarize and create a funnel array of steps
| summarize 
  funnel = array (
    record(step="Add to cart", count=countIf(`add_to_cart`>=0)),
    record(step="Place order", count=countIf(`add_to_cart`>=0 and `place_order`>`add_to_cart`)),
    record(step="Payment", count=countIf(`add_to_cart`>=0 and `place_order`>`add_to_cart` and `payment`>`place_order`))
  )
// // Expand events into separate records
| expand funnel
| fieldsFlatten funnel
| fieldsRemove funnel

```

[Example](https://wkf10640.apps.dynatrace.com/ui/intent/dynatrace.notebooks/view-query#%7B%22visualization%22%3A%22table%22%2C%22visualizationSettings%22%3A%7B%22table%22%3A%7B%22columnOrder%22%3A%5B%22%5B%5C%22funnel.step%5C%22%5D%22%2C%22%5B%5C%22funnel.count%5C%22%5D%22%5D%7D%7D%2C%22dt.timeframe%22%3A%7B%22from%22%3A%22now()-7d%22%2C%22to%22%3A%22now()%22%7D%2C%22dt.query%22%3A%22data%20%5Cn%20%20record(timestamp%20%3D%20now()-30m%2C%20session%3D%5C%22session1%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22add_to_cart%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-25m%2C%20session%3D%5C%22session1%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22place_order%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-20m%2C%20session%3D%5C%22session1%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22payment%5C%22)%2C%5Cn%20%20record(timestamp%20%3D%20now()-30m%2C%20session%3D%5C%22session2%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22add_to_cart%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-25m%2C%20session%3D%5C%22session2%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22place_order%5C%22)%2C%5Cn%20%20%2F%2F%20this%20will%20not%20be%20counted%20in%20the%20funnel%5Cn%20%20record(timestamp%20%3D%20now()-30m%2C%20session%3D%5C%22session_without_first_event%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22place_order%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-25m%2C%20session%3D%5C%22session_without_first_event%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22payment%5C%22)%2C%5Cn%20%20%2F%2F%20session%20with%20incorrect%20order%5Cn%20%20record(timestamp%20%3D%20now()-20m%2C%20session%3D%5C%22session_with_incorrect_order%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22add_to_cart%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-25m%2C%20session%3D%5C%22session_with_incorrect_order%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22place_order%5C%22)%2C%20%5Cn%20%20record(timestamp%20%3D%20now()-30m%2C%20session%3D%5C%22session_with_incorrect_order%5C%22%2C%20%60event.provider%60%3D%5C%22myapp%5C%22%2C%20%60event.type%60%3D%5C%22payment%5C%22)%5Cn%20%20%5Cn%7C%20filter%20startsWith(event.provider%2C%5C%22myapp%5C%22)%5Cn%7C%20sort%20session%2C%20timestamp%20asc%20%5Cn%5Cn%2F%2F%20Summarize%20event%20by%20session%20into%20an%20array%2C%20so%20we%20have%20steps%20in%20an%20array%20for%20each%20session%5Cn%7C%20summarize%20steps%20%3D%20collectArray(event.type)%2C%20by%3A%7B%20session%20%7D%5Cn%5Cn%2F%2F%20Create%20position%20of%20each%20step%5Cn%7C%20fieldsAdd%20%5Cn%20%20%20%20%60add_to_cart%60%20%3D%20arrayIndexOf(steps%2C%5C%22add_to_cart%5C%22)%2C%5Cn%20%20%20%20%60place_order%60%20%3D%20arrayIndexOf(steps%2C%5C%22place_order%5C%22)%2C%5Cn%20%20%20%20%60payment%60%20%3D%20arrayIndexOf(steps%2C%5C%22payment%5C%22)%5Cn%2F%2F%20Replace%20-1%20with%20null%20so%20we%20can%20compare%20order%20%20%20%20%5Cn%7C%20fieldsAdd%20%20%20%20%20%5Cn%20%20%20%20%60add_to_cart%60%20%3D%20if(%60add_to_cart%60%3E%3D0%2C%20%60add_to_cart%60%2C%20else%3A%20null)%2C%5Cn%20%20%20%20%60place_order%60%20%3D%20if(%60place_order%60%3E%3D0%2C%20%60place_order%60%2C%20else%3A%20null)%2C%5Cn%20%20%20%20%60payment%60%20%3D%20if(%60payment%60%3E%3D0%2C%20%60payment%60%2C%20else%3A%20null)%5Cn%5Cn%2F%2F%20Summarize%20and%20create%20a%20funnel%20array%20of%20steps%5Cn%7C%20summarize%20%5Cn%20%20funnel%20%3D%20array%20(%5Cn%20%20%20%20record(step%3D%5C%22Add%20to%20cart%5C%22%2C%20count%3DcountIf(%60add_to_cart%60%3E%3D0))%2C%5Cn%20%20%20%20record(step%3D%5C%22Place%20order%5C%22%2C%20count%3DcountIf(%60add_to_cart%60%3E%3D0%20and%20%60place_order%60%3E%60add_to_cart%60))%2C%5Cn%20%20%20%20record(step%3D%5C%22Payment%5C%22%2C%20count%3DcountIf(%60add_to_cart%60%3E%3D0%20and%20%60place_order%60%3E%60add_to_cart%60%20and%20%60payment%60%3E%60place_order%60))%5Cn%20%20)%5Cn%2F%2F%20%2F%2F%20Expand%20events%20into%20separate%20records%5Cn%7C%20expand%20funnel%5Cn%7C%20fieldsFlatten%20funnel%5Cn%7C%20fieldsRemove%20funnel%22%2C%22hideInput%22%3Afalse%2C%22sourceApplication%22%3A%22dynatrace.notebooks%22%7D) in the playground

Does anyone know a better solution?&nbsp;[@KlausEnzenhofer](https://community.dynatrace.com/user/316)

---

<div class="post-metadata">

**Author:** ![DanielS](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@DanielS](https://community.dynatrace.com/u/DanielS)\
**Post date:** [September 9, 2025, 11:51pm UTC](https://community.dynatrace.com/t/create-funnels-in-new-dashboards-using-dql-queries/52890/2 "2025-09-09T23:51:45Z")

</div>

Great Work&nbsp;[@Julius\_Loman](https://community.dynatrace.com/user/3364)&nbsp;. I’ve only added percentage to the code:

```markup
data 
  record(timestamp = now()-30m, session="session1", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session1", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-20m, session="session1", `event.provider`="myapp", `event.type`="payment"),
  record(timestamp = now()-30m, session="session2", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session2", `event.provider`="myapp", `event.type`="place_order"),
  // this will not be counted in the funnel
  record(timestamp = now()-30m, session="session_without_first_event", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-25m, session="session_without_first_event", `event.provider`="myapp", `event.type`="payment"),
  // session with incorrect order
  record(timestamp = now()-20m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-30m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="payment")

| filter startsWith(event.provider,"myapp")
| sort session, timestamp asc 

// Summarize event by session into an array, so we have steps in an array for each session
| summarize steps = collectArray(event.type), by:{ session }

// Create position of each step
| fieldsAdd 
    `add_to_cart` = arrayIndexOf(steps,"add_to_cart"),
    `place_order` = arrayIndexOf(steps,"place_order"),
    `payment` = arrayIndexOf(steps,"payment")
// Replace -1 with null so we can compare order    
| fieldsAdd     
    `add_to_cart` = if(`add_to_cart`>=0, `add_to_cart`, else: null),
    `place_order` = if(`place_order`>=0, `place_order`, else: null),
    `payment` = if(`payment`>=0, `payment`, else: null)

// Summarize and create a funnel array of steps
| summarize 
  total_paso_0 = toDouble(countIf(`add_to_cart`>=0)),
  funnel = array (
    record(step="Add to cart", count=countIf(`add_to_cart`>=0)),
    record(step="Place order", count=countIf(`add_to_cart`>=0 and `place_order`>`add_to_cart`)),
    record(step="Payment", count=countIf(`add_to_cart`>=0 and `place_order`>`add_to_cart` and `payment`>`place_order`))
  )
// // Expand events into separate records
| expand funnel
| fieldsFlatten funnel
| fieldsRemove funnel
// Calculate percentage
| fieldsAdd percentage = round((toDouble(`funnel.count`)/total_paso_0)*100, decimals: 2)
// Select, rename, and order the columns
| fields step = `funnel.step`, count = `funnel.count`, percentage

```

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [September 10, 2025, 5:52pm UTC](https://community.dynatrace.com/t/create-funnels-in-new-dashboards-using-dql-queries/52890/3 "2025-09-10T17:52:34Z")

</div>

Here is my idea for more generic query where “ifs” for each step are not needed for 1st case, so order is not obligatory (repetitions are allowed):

```markup
data 
  record(timestamp = now()-30m, session="session0", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-30m, session="session1", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session1", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-20m, session="session1", `event.provider`="myapp", `event.type`="payment"),
  record(timestamp = now()-30m, session="session2", `event.provider`="myapp", `event.type`="add_to_cart"), 
  record(timestamp = now()-25m, session="session2", `event.provider`="myapp", `event.type`="place_order"),
  // this will not be counted in the funnel
  record(timestamp = now()-30m, session="session_without_first_event", `event.provider`="myapp", `event.type`="place_order"), 
  record(timestamp = now()-25m, session="session_without_first_event", `event.provider`="myapp", `event.type`="payment")   

// Summarize event by session into an array, so we have steps in an array for each session
| summarize steps = collectArray(event.type), by:{ session }

| fieldsAdd stepsOrder=array(record(id="add_to_cart", name="Add to cart"), record(id="place_order", name="Place order"), record(id="payment", name="Payment"))

| fieldsAdd p = stepsOrder[][id]
| fieldsAdd p = arrayRemoveNulls(iCollectArray(if(arrayIndexOf(steps, p[])>-1, record(name=stepsOrder[][name], index=iIndex()))))
| filterOut iAny(p[][index]!=iIndex())
| expand p
| summarize { cnt = count() }, by: { index=p[index], name=p[name] }
| sort index asc

```

Funnel definion is an array (stepsOrder) with records carrying identification of step and its name. Order in array also defines oder is steps in funnel.

Fist step is to collect step ids for each session.

Next step is get array of identified steps:

```markup
if(arrayIndexOf(steps, p[])>-1, record(name=stepsOrder[][name], index=iIndex()))

```

If step was present we get record with step name and its index.

If we eliminate nulls from the table and intermediate step was missing, index remembered will be different actual in the table. This can be used to eliminate sessions with holes

```markup
| filterOut iAny(p[][index]!=iIndex())

```

Last part is to expand and count steps. Because we were checking template vs. actual steps, duplicates are not counted. And finally we can just sort by step index.

Re visualization: IMHO most appropiate way to show funnel out of existing ones is “categorical chart”. It shows data in order as provided, so funnel should be also visible

 ![krzysztof_hoja_0-1757526272389.png](https://global.discourse-cdn.com/dynatrace/original/3X/f/4/f44adea0dc3b0aa0912991f8197a8f60f43f065c.png)

Note: I used string as id as in original example, but it does not have to be simple type. In more advanced cases we can construct id as a complex record in our funnel definition and in actual data. Finding such ids in array works too.

I will also think about case where order os steps is important.
