Azure Application Insights查询-如何计算总数百分比 [英] Azure Application Insights Query - How to calculate percentage of total
问题描述
我正在尝试在输出表中创建一行,以计算项目总数的百分比:
I'm trying to create a row in an output table that would calculate percentage of total items:
Something like this:
ITEM | COUNT | PERCENTAGE
item 1 | 4 | 80
item 2 | 1 | 20
我可以很容易地获得一个包含ITEM和COUNT行的表,但是我不知道如何将总数(在这种情况下为5)作为一个数字来计算,因此我可以计算%列中的百分比.
I can easily get a table with rows of ITEM and COUNT, but I can't figure out how to get total (5 in this case) as a number so I can calculate percentage in column %.
someTable
| where name == "Some Name"
| summarize COUNT = count() by ITEM = tostring( customDimensions.["SomePar"])
| project ITEM, COUNT, PERCENTAGE = (C/?)*100
有什么想法吗?谢谢.
推荐答案
创建这样的查询有点混乱.
It's a bit messy to create a query like that.
我已经基于AI中的customEvents表完成了它.因此,请看一下是否可以使其适应您的特定情况.
I've done it bases on the customEvents table in AI. So take a look and see if you can adapt it to your specific situation.
您必须创建一个包含记录总数的表,然后您必须联接该表.由于您只能在公共列上进行联接,因此需要一列始终具有相同值的列.我为此选择了appName.
You have to create a table that contains the total count of records, you then have to join this table. Since you can join only on a common column you need a column that has always the same value. I choose appName for that.
因此整个查询如下:
let totalEvents = customEvents
// | where name contains "Opened form"
| summarize count() by appName
| project appName, count_ ;
customEvents
// | where name contains "Opened form"
| join kind=leftouter totalEvents on appName
| summarize count() by name, count_
| project name, totalCount = count_ , itemCount = count_1, percentage = (todouble(count_1) * 100 / todouble(count_))
如果需要过滤器,则必须将其应用于两个表.
If you need a filter you have to apply it to both tables.
这将输出:
这篇关于Azure Application Insights查询-如何计算总数百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!