Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to "flatten" KQL results into summary columns?

Given the following dataset, is there a simple/efficient way to produce a summary table in like the following using KQL, ideally without knowing the actual colours to be used in advance (i.e. column names are generated from the data values encountered)?

datatable ( name: string, colour: string )[
  "alice", "blue",
  "bob", "green",
  "bob", "blue",
  "alice", "red",
  "charlie", "red",
  "alice", "blue",
  "charlie", "red",
  "bob", "green"
]

+---------+------+-------+-----+
| name    | blue | green | red |
+---------+------+-------+-----+
| alice   |    2 |     0 |   1 |
| bob     |    1 |     2 |   0 |
| charlie |    0 |     0 |   2 |
+---------+------+-------+-----+

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Pivot plugin

datatable ( name: string, colour: string )[
  "alice", "blue",
  "bob", "green",
  "bob", "blue",
  "alice", "red",
  "charlie", "red",
  "alice", "blue",
  "charlie", "red",
  "bob", "green"
]
| evaluate pivot(colour, count(), name)
name blue green red
alice 2 0 1
bob 1 2 0
charlie 0 0 2

Fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading