# Reverse of group function

**URL:** <https://forum.kx.com/t/reverse-of-group-function/11403>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [November 29, 2016, 7:51pm UTC](https://forum.kx.com/t/reverse-of-group-function/11403 "2016-11-29T19:51:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![evd](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@evd](https://forum.kx.com/u/evd)\
**Post date:** [November 29, 2016, 7:51pm UTC](https://forum.kx.com/t/reverse-of-group-function/11403/1 "2016-11-29T19:51:00Z")

</div>

q) di:group li:1 2 3 3 2 1

1| 0 5

2| 1 4

3| 2 3

How having di get li? Is there better than&nbsp;{@[x;y;:;z]}/[(sum count each di)#0N;value di;key di] ?

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [November 29, 2016, 8:14pm UTC](https://forum.kx.com/t/reverse-of-group-function/11403/2 "2016-11-29T20:14:00Z")

</div>

one way

q)di:group li:10000000?10000

q)li~(where count each di)iasc raze di

1b

q)\ts (where count each di)iasc raze di

1401 402784640

q)\ts {@[x;y;:;z]}/[(sum count each di)#0N;value di;key di]&nbsp;

121931 402670528

---

<div class="post-metadata">

**Author:** ![evd](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@evd](https://forum.kx.com/u/evd)\
**Post date:** [November 29, 2016, 8:46pm UTC](https://forum.kx.com/t/reverse-of-group-function/11403/3 "2016-11-29T20:46:00Z")

</div>

It is great. I used to apply where function to binary lists and forgot his affect for integer lists and dictionaries. Thanks for reminding me.

---

<div class="post-metadata">

**Author:** ![Attila](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Attila](https://forum.kx.com/u/Attila)\
**Post date:** [November 29, 2016, 10:47pm UTC](https://forum.kx.com/t/reverse-of-group-function/11403/4 "2016-11-29T22:47:00Z")

</div>

another way, ie amend can be okay if the over is avoided

q)\ts (where count each di)iasc raze di

3440 402784576

q)\ts @[count[r]#first key di;r:raze di;:;where count each di]

497 402653840

>
