# Remove Duplicate Entries in Custom Metric Data Using DQL

**URL:** <https://community.dynatrace.com/t/remove-duplicate-entries-in-custom-metric-data-using-dql/52726>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed\
**Created:** [July 31, 2025, 4:28am UTC](https://community.dynatrace.com/t/remove-duplicate-entries-in-custom-metric-data-using-dql/52726 "2025-07-31T04:28:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![knallapa](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@knallapa](https://community.dynatrace.com/u/knallapa)\
**Post date:** [July 31, 2025, 4:28am UTC](https://community.dynatrace.com/t/remove-duplicate-entries-in-custom-metric-data-using-dql/52726/1 "2025-07-31T04:28:54Z")

</div>

**How can I eliminate duplications in DQL when working with timeseries custom metric data filtered by conditions?**  
USECASE: Loading Custom metrics in below query 10 times in timeseries is killing DQL Storage bucket. I attempted to use variables to reuse the metric, but it didn’t help—each usage resulted in new data buckets being created. This caused the query to explode to over **500 million data points Error from Dynatrace Limitations,** even though the source dataset only contains 43,000 records with 11 columns in the table.

For Above Query Nothing worked for me: Tried variables, Problems i faced is :

- can’t fetch a metric once and reuse it with conditional logic applying filters.
- can’t assign a timeseries result to a variable inside fetch.
- can’t use let to define reusable filters inside fetch.

**Query is :**

timeseries METRIC\_A\_approved = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeA” AND  
(responseCode == “0” OR responseCode == “00”) AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }

| join [  
timeseries METRIC\_A\_total = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeA” AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_A\_total }, kind: outer

| join [  
timeseries METRIC\_B\_approved = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeB” AND  
(responseCode == “0” OR responseCode == “00”) AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_B\_approved }, kind: outer

| join [  
timeseries METRIC\_B\_total = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeB” AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_B\_total }, kind: outer

| join [  
timeseries METRIC\_B\_approved\_subgroup = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeB” AND  
(responseCode == “0” OR responseCode == “00”) AND  
(categoryCode in [“1001”, “1002”, “1003”, “1004”, “1005”]) AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_B\_approved\_subgroup }, kind: outer

| join [  
timeseries METRIC\_B\_total\_subgroup = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeB” AND  
(categoryCode in [“1001”, “1002”, “1003”, “1004”, “1005”]) AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_B\_total\_subgroup }, kind: outer

| join [  
timeseries METRIC\_B\_approved\_domestic = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeB” AND  
(responseCode == “0” OR responseCode == “00”) AND  
categoryCode == “2001” AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_B\_approved\_domestic }, kind: outer

| join [  
timeseries METRIC\_B\_total\_domestic = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeB” AND  
categoryCode == “2001” AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_B\_total\_domestic }, kind: outer

| join [  
timeseries METRIC\_B\_approved\_crossborder = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeB” AND  
(responseCode == “0” OR responseCode == “00”) AND  
categoryCode == “2002” AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_B\_approved\_crossborder }, kind: outer

| join [  
timeseries METRIC\_B\_total\_crossborder = sum(  
`custom.app-metrics.transaction.data`,  
scalar: true,  
filter: {  
txType == “TypeB” AND  
categoryCode == “2002” AND  
(isNull($Entity) OR $Entity == “” OR entity == $Entity)  
}  
), by: { entity }  
], on: { entity }, fields: { METRIC\_B\_total\_crossborder }, kind: outer

| fieldsAdd  
Rate\_A = if(coalesce(METRIC\_A\_total, 0) == 0, 0, 100 \* coalesce(METRIC\_A\_approved, 0) / coalesce(METRIC\_A\_total, 0)),  
Rate\_B = if(coalesce(METRIC\_B\_total, 0) == 0, 0, 100 \* coalesce(METRIC\_B\_approved, 0) / coalesce(METRIC\_B\_total, 0)),  
Rate\_B\_subgroup = if(coalesce(METRIC\_B\_total\_subgroup, 0) == 0, 0, 100 \* coalesce(METRIC\_B\_approved\_subgroup, 0) / coalesce(METRIC\_B\_total\_subgroup, 0)),  
Rate\_B\_domestic = if(coalesce(METRIC\_B\_total\_domestic, 0) == 0, 0, 100 \* coalesce(METRIC\_B\_approved\_domestic, 0) / coalesce(METRIC\_B\_total\_domestic, 0)),  
Rate\_B\_crossborder = if(coalesce(METRIC\_B\_total\_crossborder, 0) == 0, 0, 100 \* coalesce(METRIC\_B\_approved\_crossborder, 0) / coalesce(METRIC\_B\_total\_crossborder, 0))

| filter not(isNull(entity) or entity == “”)  
| fieldsAdd  
Entity = entity,  
A.Total = toLong(coalesce(METRIC\_A\_total, 0)),  
A.Rate = concat(toString(round(coalesce(Rate\_A, 0), decimals: 2)), “%”),  
B.Total = toLong(coalesce(METRIC\_B\_total, 0)),  
B.Rate = concat(toString(round(coalesce(Rate\_B, 0), decimals: 2)), “%”),  
B.Total.Sub = toLong(coalesce(METRIC\_B\_total\_subgroup, 0)),  
B.Rate.Sub = concat(toString(round(coalesce(Rate\_B\_subgroup, 0), decimals: 2)), “%”),  
B.Total.Dom = toLong(coalesce(METRIC\_B\_total\_domestic, 0)),  
B.Rate.Dom = concat(toString(round(coalesce(Rate\_B\_domestic, 0), decimals: 2)), “%”),  
B.Total.XB = toLong(coalesce(METRIC\_B\_total\_crossborder, 0)),  
B.Rate.XB = concat(toString(round(coalesce(Rate\_B\_crossborder, 0), decimals: 2)), “%”)

| fields Entity, A.Total, A.Rate, B.Total, B.Rate, B.Total.Dom, B.Rate.Dom, B.Total.XB, B.Rate.XB, B.Total.Sub, B.Rate.Sub  
| sort A.Rate desc

---

<div class="post-metadata">

**Author:** ![izabelarokita](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/izabelarokita/32/41812_2.png) [@izabelarokita](https://community.dynatrace.com/u/izabelarokita)\
**Post date:** [December 17, 2025, 10:26am UTC](https://community.dynatrace.com/t/remove-duplicate-entries-in-custom-metric-data-using-dql/52726/2 "2025-12-17T10:26:30Z")

</div>

Hey&nbsp;[@knallapa](https://community.dynatrace.com/user/87812)&nbsp;,  
I just wanted to check in and see if you still need help with this. If so, I’d be happy to look into it for you!&nbsp;:blush:  
Please let me know what works best for you.
