# Counting the last time a supplier transacted

**URL:** <https://discuss.elastic.co/t/counting-the-last-time-a-supplier-transacted/97878>\
**Category:** Kibana\
**Created:** [August 22, 2017, 8:45am UTC](https://discuss.elastic.co/t/counting-the-last-time-a-supplier-transacted/97878 "2017-08-22T08:45:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![woodbine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woodbine/32/35989_2.png) [@woodbine](https://discuss.elastic.co/u/woodbine)\
**Post date:** [August 22, 2017, 8:45am UTC](https://discuss.elastic.co/t/counting-the-last-time-a-supplier-transacted/97878/1 "2017-08-22T08:45:14Z")

</div>

I have some accounts payable transactions between a buyer and their suppliers. We want to monitor the last time a supplier transacted so that we can get rid of old suppliers in the database. I'm able to count the number of suppliers who transacted (and their total value), but I can't work out how to do a count on a max date by month.

Is this a situation where the best answer is to create a new field in the index?

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [August 22, 2017, 10:34pm UTC](https://discuss.elastic.co/t/counting-the-last-time-a-supplier-transacted/97878/2 "2017-08-22T22:34:31Z")

</div>

I would recommend using a data table, creating an aggregation on the min of the transaction date, then split the rows on the buyer.

Here is the sample data I used in Console:

```auto
POST /discuss-97878/transaction
{
  "created_at": "2017-05-01",
  "buyer": "foo"
}

POST /discuss-97878/transaction
{
  "created_at": "2017-04-01",
  "buyer": "foo"
}

# oldest foo
POST /discuss-97878/transaction
{
  "created_at": "2017-03-01",
  "buyer": "foo"
}

# oldest bar
POST /discuss-97878/transaction
{
  "created_at": "2017-05-02",
  "buyer": "bar"
}

POST /discuss-97878/transaction
{
  "created_at": "2017-06-02",
  "buyer": "bar"
}

POST /discuss-97878/transaction
{
  "created_at": "2017-07-02",
  "buyer": "bar"
}

POST /discuss-97878/transaction
{
  "created_at": "2017-06-03",
  "buyer": "baz"
}

POST /discuss-97878/transaction
{
  "created_at": "2017-05-03",
  "buyer": "baz"
}

POST /discuss-97878/transaction
{
  "created_at": "2017-07-03",
  "buyer": "baz"
}

```

Then, I setup the visualization:

![45](https://us1.discourse-cdn.com/elastic/original/3X/f/f/ff79321d4665a87ffa869b6e04c24a42c9c47dd1.png)

---

<div class="post-metadata">

**Author:** ![woodbine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/woodbine/32/35989_2.png) [@woodbine](https://discuss.elastic.co/u/woodbine)\
**Post date:** [August 30, 2017, 9:26pm UTC](https://discuss.elastic.co/t/counting-the-last-time-a-supplier-transacted/97878/3 "2017-08-30T21:26:19Z")

</div>

Thank you that's perfect.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 27, 2017, 9:26pm UTC](https://discuss.elastic.co/t/counting-the-last-time-a-supplier-transacted/97878/4 "2017-09-27T21:26:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
