azure data explorer function with parameter for 'by' condition

Romain Miralles 21 Reputation points
2021-01-06T03:32:07.277+00:00

Hi,

is there a way to add parameter to my ADX function in order to summarize value by different dimension. for example let say I have country and city in my table. I would like to create a function with a parameter to specificy if it needs to summarize by country/city or country only.

So basically use the same function to run something like thant

|summarize count() by country,city

or
|summarize count() by country

I am looking for a way to pass the variable after the 'by' statement

Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
502 questions
0 comments No comments
{count} votes

Accepted answer
  1. PRADEEPCHEEKATLA-MSFT 84,381 Reputation points Microsoft Employee
    2021-01-06T08:12:10.797+00:00

    Hello @Romain Miralles ,

    Welcome to the Microsoft Q&A platform.

    You can't pass a value dynamically, so the best way to achieve what you want is to write the function this way:

    let SummarizeByCity = Table | where param == "City" | ... | summarize count() by city;  
    let SummarizeByCountry = Table | where param == "Country" | ... | summarize count() by country;  
    union SummarizeByCity, SummarizeByCountry  
    

    Note: This will be optimal performance-wise, as Kusto will only evaluate the relevant branch (City OR Country, but not both), because of the where clauses.

    For more detail, refer aggregation functions - count() and dcount().

    Hope this helps. Do let us know if you any further queries.

    ------------

    • Please accept an answer if correct. Original posters help the community find answers faster by identifying the correct answer. Here is how.
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification.

0 additional answers

Sort by: Most helpful