# Assign Multiple Variables in DQL Queries Following Best Practices

**URL:** <https://community.dynatrace.com/t/assign-multiple-variables-in-dql-queries-following-best-practices/50816>\
**Category:** DQL\
**Tags:** dql\
**Created:** [March 20, 2025, 5:05pm UTC](https://community.dynatrace.com/t/assign-multiple-variables-in-dql-queries-following-best-practices/50816 "2025-03-20T17:05:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moonrox](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@Moonrox](https://community.dynatrace.com/u/Moonrox)\
**Post date:** [March 20, 2025, 5:05pm UTC](https://community.dynatrace.com/t/assign-multiple-variables-in-dql-queries-following-best-practices/50816/1 "2025-03-20T17:05:44Z")

</div>

I am working on a DQL query to gather and store 2 variables and then create a trending variable.Please advise if this is the best way to solve this problem.// Fetch Active problems from the last 7 daysfetch dt.davis.problems, from: now()-7d| fieldsAdd entity\_tags| expand entity\_tags| filter event.status ==&nbsp;“ACTIVE”| summarize count(), alias:last7DayCount// Fetch Active problems from the 8-14 days ago| append [fetch dt.davis.problems, from: now()-14d, to: now()-8d| fieldsAdd entity\_tags| expand entity\_tags| filter event.status ==&nbsp;“ACTIVE”| summarize count(), alias:last14DayCount]// Combine results into a single output| summarize sum(last7DayCount), alias:last7DayCount, sum(last14DayCount), alias:last14DayCount| fields last7DayCount, last14DayCount// Calculate trend using conditional logic with named parameters| fieldsAdd trend =&nbsp;if(condition: last7DayCount \> last14DayCount, then:&nbsp;“Up”,&nbsp;else:&nbsp;if(condition: last7DayCount \< last14DayCount, then:&nbsp;“Down”,&nbsp;else:&nbsp;“Stable”))// Display results| fields last14DayCount, last7DayCount, trend

---

<div class="post-metadata">

**Author:** ![marco\_irmer](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/marco_irmer/32/3038_2.png) [@marco\_irmer](https://community.dynatrace.com/u/marco_irmer)\
**Post date:** [March 24, 2025, 10:51pm UTC](https://community.dynatrace.com/t/assign-multiple-variables-in-dql-queries-following-best-practices/50816/2 "2025-03-24T22:51:37Z")

</div>

I would suggest running a single fetch going back the full 14 days and then using summarize combined with countIf. This can be used to create two separate count, one for the last 7 days, and one for the prior 7 days (based on the start time perhaps). You can then use fieldsAdd with an if statement that compares the two counts to determine which way the trend is moving. I would also urge caution around the use of the expand command, as well as filtering on active==true in your query, as both of these might generate undesirable results depending on what you are trying to accomplish here.
