# Historical data in Metric events

**URL:** <https://community.dynatrace.com/t/historical-data-in-metric-events/37580>\
**Category:** Alerting\
**Tags:** problem-notification, anomaly-detection, problems-classic\
**Created:** [December 5, 2022, 10:17pm UTC](https://community.dynatrace.com/t/historical-data-in-metric-events/37580 "2022-12-05T22:17:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hv](https://avatars.discourse-cdn.com/v4/letter/h/f19dbf/32.png) [@hv](https://community.dynatrace.com/u/hv)\
**Post date:** [December 5, 2022, 10:17pm UTC](https://community.dynatrace.com/t/historical-data-in-metric-events/37580/1 "2022-12-05T22:17:50Z")

</div>

Hi,

I’m trying to create an alert (metric event) based on the average value of a builtin metric (eg: builtin:containers.cpu.usageMilliCores) in last X days using metric selector.

How can time be passed into metric selector?

See there is an equivalent of **&from=now-5m** in metric selector like in the API call below.

https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin:host.cpu.(usage,idle):filter(or(eq(%22dt.entity.host%22,%22HOST-0990886B7D39FE29%22),eq(%22dt.entity.host%22,%22HOST-0956C3557E9109C1%22)))&from=now-5m’

---

<div class="post-metadata">

**Author:** ![hv](https://avatars.discourse-cdn.com/v4/letter/h/f19dbf/32.png) [@hv](https://community.dynatrace.com/u/hv)\
**Post date:** [December 7, 2022, 5:18pm UTC](https://community.dynatrace.com/t/historical-data-in-metric-events/37580/2 "2022-12-07T17:18:54Z")

</div>

We ended up using a combination of&nbsp; **api/v2/metrics** and&nbsp; **/api/v2/events/ingest** to check the data and alert.
