# To find top 5 values and All value on selection of radio button on the basis of same field in Vega-lite using Kibana

**URL:** <https://discuss.elastic.co/t/to-find-top-5-values-and-all-value-on-selection-of-radio-button-on-the-basis-of-same-field-in-vega-lite-using-kibana/327066>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [March 6, 2023, 10:38am UTC](https://discuss.elastic.co/t/to-find-top-5-values-and-all-value-on-selection-of-radio-button-on-the-basis-of-same-field-in-vega-lite-using-kibana/327066 "2023-03-06T10:38:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ysattvik](https://avatars.discourse-cdn.com/v4/letter/y/3da27b/32.png) [@ysattvik](https://discuss.elastic.co/u/ysattvik)\
**Post date:** [March 6, 2023, 10:38am UTC](https://discuss.elastic.co/t/to-find-top-5-values-and-all-value-on-selection-of-radio-button-on-the-basis-of-same-field-in-vega-lite-using-kibana/327066/1 "2023-03-06T10:38:54Z")

</div>

Hi Team,

I am trying to implement selection options using radio button to show the top 5 values and other radio button shows the all the values available in that field using Vega-lite. It can be easily explained by this image.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/8/48a9ed9d3bc78194c870ea4088f621ac43f0e6c8.png)

Since, I have to filtered out the top 5 value from the same field and on the selection of other radio button all the available options should display in the visualization.  
I am facing issue in implementing this.  
please help me with some demo code to fulfil my requirement.

My code is....

```auto
"transform": [
    {
      "window": [{
        "op": "rank",
        "as": "rank"
      }],
      "sort": [{ "field": "_source.BeneficiaryType.shortCode","order": "descending" }]
    }, {
      "filter": "datum.rank >=5"
    }
  ],
  encoding: {
    x: {
      field: _source.BeneficiaryType.shortCode
      type: nominal
      title: Applicant type
    }
    y: {
      field: _source.Applicant.AppliedLoanAmount
      type: quantitative
      title: Applied Loan Amount (₹ Cr.)
      aggregate: sum
    },
     "color": {"value": "#6495ED "},
     "tooltip": [
      {
      aggregate: sum
      "field": "_source.Applicant.AppliedLoanAmount",
      "type": "quantitative"
      title: Applied Loan Amount (₹ Cr.)
      }
      ] 
  },
  "layer": [
  {
    "mark": "bar"
  }, {
    "mark": {
      "type": "text",
      "align": "center",
      "baseline": "middle",
      "dx": -5
      "dy": -5
      angle: 0
      fontWeight: bold
    },
    "encoding": {
      "text": {"field": "_source.Applicant.AppliedLoanAmount", "type": "quantitative", "aggregate": "sum"}
       "color": {"value": "black "}
    },
  "selection": {
    "selector006": {
      "type": "single",
      "fields": ["Select"],
      "bind": {
        "input": "radio",
        "options": ["_source.Applicant.ApprovedLoanAmount","Approved_Loan"],
        "labels":[" Top 5", "All"]
        "name": " "
      },
     "init": {"Select": "_source.Applicant.ApprovedLoanAmount"}
    }
  },
  "transform": [
    {
      "fold": ["_source.Applicant.ApprovedLoanAmount", "Approved_Loan"],
      "as": ["Select", "value"]
    },
    {"filter": {"selection": "selector006"}}
  ]
  
  }
  ]

```

---

<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 3, 2023, 10:39am UTC](https://discuss.elastic.co/t/to-find-top-5-values-and-all-value-on-selection-of-radio-button-on-the-basis-of-same-field-in-vega-lite-using-kibana/327066/2 "2023-04-03T10:39:53Z")

</div>

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