# How to create advanced visualization in Kibana?

**URL:** <https://discuss.elastic.co/t/how-to-create-advanced-visualization-in-kibana/300534>\
**Category:** Kibana\
**Created:** [March 24, 2022, 8:15am UTC](https://discuss.elastic.co/t/how-to-create-advanced-visualization-in-kibana/300534 "2022-03-24T08:15:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ninamarie0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ninamarie0/32/103449_2.png) [@ninamarie0](https://discuss.elastic.co/u/ninamarie0)\
**Post date:** [March 24, 2022, 8:15am UTC](https://discuss.elastic.co/t/how-to-create-advanced-visualization-in-kibana/300534/1 "2022-03-24T08:15:27Z")

</div>

Hi.  
I am new to Kibana and are struggling to find out how to create more "advanced" visualizations.  
I have already created a dashboard of more simple metrics and charts, but now i want to take the next step.

My data consists of one event per user which sign in to different clients.  
Basically, what i want to do is to count the number of users which has signed in into more than one client the last week.  
So it would be something like this:

1. GROUP all events BY SubjectID (hence one group per unique subjectID)
2. COUNT all the groups where UNIQUE clientID \> 1

How can I do this in a Kibana visualization? What kind of visualization should i use?  
In advance, thanks for your help!

---

<div class="post-metadata">

**Author:** ![Marta\_Bondyra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marta_bondyra/32/102122_2.png) [@Marta\_Bondyra](https://discuss.elastic.co/u/Marta_Bondyra)\
**Post date:** [March 24, 2022, 10:09am UTC](https://discuss.elastic.co/t/how-to-create-advanced-visualization-in-kibana/300534/2 "2022-03-24T10:09:24Z")

</div>

Hi, this is in fact quite complex visualization and at this moment you can use Vega to achieve it. It would be something like this (example fore ecommerce data):

```auto
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "url": {
      "%context%": true,
      "index": "kibana_sample_data_ecommerce",
      "body": {
        "aggs": {
          "groupedCategories": {
            "terms": {"field": "category.keyword", "size": 100000}, //GROUP all doc BY category.keyword 
            "aggs": {
              "uid": {"cardinality": {"field": "customer_id"}}, // COUNT all the groups with customer_id cardinality
              "sales_bucket_filter": {
                "bucket_selector": {
                  "buckets_path": {"uniqueCustomerId": "uid"},
                  "script": "params.uniqueCustomerId > 20" // where unique customerId > 20 (replace with 1 in your case)
                }
              },
              "counter": {
                "bucket_script": {"buckets_path": "uid", "script": "return 1"} // count the remaining groups
              }
            }
          },
          "count": {"sum_bucket": {"buckets_path": "groupedCategories>counter"}} // pass to the result
        },
        "size": 0
      }
    },
    "format": {"property": "aggregations.count"}
  },
  "encoding": {"text": {"field": "value", "type": "quantitative"}},
  "mark": { // styling, refer to vega documentation to change it
    "type": "text",
    "fill": "red",
    "fontSize": 100,
    "fillOpacity": 1,
    "x": 10,
    "y": 10
  },
  "config": {"view": {"stroke": "transparent"}}
}

```

![Screenshot 2022-03-24 at 11.08.47](https://us1.discourse-cdn.com/elastic/original/3X/c/b/cb35298aad4dacd36b5716e348c35276d16449ba.png)

Let me know if that helps, it should work only y replacing the field names I used for your own 🙂

---

<div class="post-metadata">

**Author:** ![ninamarie0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ninamarie0/32/103449_2.png) [@ninamarie0](https://discuss.elastic.co/u/ninamarie0)\
**Post date:** [March 24, 2022, 12:38pm UTC](https://discuss.elastic.co/t/how-to-create-advanced-visualization-in-kibana/300534/3 "2022-03-24T12:38:38Z")

</div>

This is working! Thank you so much, really helpful of you!! 🙂

---

<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:** [April 21, 2022, 12:38pm UTC](https://discuss.elastic.co/t/how-to-create-advanced-visualization-in-kibana/300534/4 "2022-04-21T12:38:51Z")

</div>

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