Milo_Dev
Milo_Dev

Reputation: 415

Kusto - Render Column chart as per bucket values (extend operator)

If I run the below Query to the following datatable I am getting results only as 10E for event _count>10. Is there any reason the other categories are not getting displayed in the bucket. I would like to render column chart as per the event count category. Thanks.

    | summarize event_count=count() by State
    | where event_count > 10
    | extend bucket = case (
    event_count > 10, "10E",
    event_count > 100, "100E",
    event_count > 500, "500E",
    event_count > 1000, "1000E",
    event_count > 5000, ">5000E",
    "N/A")
| project bucket```


datatable (State: string, event_count: long) [
    "VIRGIN ISLANDS",long(12),
    "AMERICAN SAMOA",long(16),
    "DISTRICT OF COLUMBIA",long(22),
    "LAKE ERIE",long(27),
    "LAKE ST CLAIR",long(32),
    "LAKE SUPERIOR",long(34),
    "RHODE ISLAND",long(51),
    "LAKE HURON",long(63),
    "CONNECTICUT",long(148)
]

Upvotes: 0

Views: 1791

Answers (1)

Avnera
Avnera

Reputation: 7618

When a condition is true in a "case" function, it doe not continue to the next one. Since all of your counts are bigger than 10, then the first category is correct for all of them. It seems that you wanted that the condition would be less or equal to, here is an example:

datatable (State: string, event_count: long) [
    "VIRGIN ISLANDS",long(12),
    "AMERICAN SAMOA",long(16),
    "DISTRICT OF COLUMBIA",long(22),
    "LAKE ERIE",long(27),
    "LAKE ST CLAIR",long(32),
    "LAKE SUPERIOR",long(34),
    "RHODE ISLAND",long(51),
    "LAKE HURON",long(63),
    "CONNECTICUT",long(148)
]
    | where event_count > 10
    | extend bucket = case (
    event_count <= 10, "10E",
    event_count <= 100, "100E",
    event_count <= 500, "500E",
    event_count <= 1000, "1000E",
    event_count <= 5000, ">5000E",
    "N/A")
| summarize sum(event_count) by bucket
| render columnchart
bucket sum_event_count
100E 257
500E 148

enter image description here

Upvotes: 3

Related Questions