Azure Knowledge Explorer – Carry out Calculation On A number of Values From Single Kusto Enter
Let’s think about a state of affairs, whereby the requirement is to search out out the share of a selected sort of values from a single enter set.
Beneath might be thought-about for instance of enter pattern knowledge and we have to discover out what proportion of dev releases and what proportion of prod launched are current within the enter knowledge.
- let demoData = datatable(Setting: string, Characteristic:string)
- [
- “dev”, “Feature1”,
- “test”, “Feature1”,
- “prod”, “Feature1”,
- “Dev”, “Feature2”,
- “test”, “Feature2”,
- “dev”, “Feature3”,
- “test”, “Feature3”,
- “prod”, “Feature3”
- ];
Strategy
As a way to obtain the answer, one has to undergo varied steps as talked about beneath,
Step 1
Get the entire variety of information from the set.
- let totalRecords = demoData
- | rely
- | challenge TotalRecords = Rely;
Step 2
Get solely these information that are of sort ‘dev’
- let devRecords = demoData
- | the place Setting =~ “dev”
- | rely
- | challenge TotalDevRecords = Rely;
Step 3
Get solely these information that are of sort ‘prod’
- let prodRecords = demoData
- | the place Setting =~ “prod”
- | rely
- | challenge TotalProdRecords=Rely;
To date we now have received all the person elements. The subsequent job is to mix all of the above talked about Three steps and generate a single outcome set and right here comes the problem.
Problem
As enter set is holding solely two columns, there is no such thing as a widespread subject in all of the above talked about three queries, and as there is no such thing as a commonality it’s considerably tough to deliver such a outcome set collectively to type a single outcome set.
Addressing the problem
Can’t we go forward and introduce some new column only for the sake of projection? Effectively, let’s see how that adjustments our above Three steps now,
Up to date Step 1
- let totalRecords = demoData
- | rely |lengthen CommonCol=“Dummy”
- | challenge CommonCol, TotalRecords = Rely;
Up to date Step 2
- let devRecords = demoData
- | the place Setting =~ “dev”
- | rely | lengthen CommonCol=“Dummy”
- | challenge CommonCol, TotalDevRecords = Rely;
Up to date Step 3
- let prodRecords = demoData
- | the place Setting =~ “prod”
- | rely|lengthen CommonCol=“Dummy”
- | challenge CommonCol, TotalProdRecords = Rely;
Now comes the ultimate step, whereby we have to deliver all of the above outcome set collectively to calculate the share.
Step 4
Combining the person outcomes to get a single outcome.
- totalRecords
- | be a part of (devRecords | be a part of prodRecords on CommonCol) on CommonCol
- | lengthen DevRecords = (TotalDevRecords * 100)/TotalRecords
- | lengthen ProdRecords = (TotalProdRecords * 100)/TotalRecords
- | challenge DevRecords, ProdRecords;
Full question
- let totalRecords = demoData
- | rely
- |lengthen CommonCol=“Dummy”
- | challenge CommonCol, TotalRecords = Rely;
- let devRecords = demoData
- | the place Setting =~ “dev”
- | rely
- | lengthen CommonCol=“Dummy”
- | challenge CommonCol, TotalDevRecords = Rely;
- let prodRecords = demoData
- | the place Setting =~ “prod”
- | rely|lengthen CommonCol=“Dummy”
- | challenge CommonCol, TotalProdRecords = Rely;
- totalRecords
- | be a part of (devRecords
- | be a part of prodRecords on CommonCol) on CommonCol
- | lengthen DevRecords = (TotalDevRecords * 100)/TotalRecords
- | lengthen ProdRecords = (TotalProdRecords * 100)/TotalRecords
- | challenge DevRecords, ProdRecords;
Consequence
On execution of the above steps, you’re going to get the specified output as proven beneath,
Hope you loved studying.
Comfortable kustoing.