8

I am trying to get summary of failures in percentages of totals, see my query below. It is good, but I want it to show me Vendor1=0.5 and Vendor2=0.5 (50% failures), and not just Vendor1=1 (one failure with 0), Vendor2=2 (two failures of 0)

datatable (Vendor:string, failure:int)
    ["Vendor1",3,
    "Vendor2",0,
    "Vendor2",0,
    "Vendor2", 7,
    "Vendor1",0,
    "Vendor2", 1]
| where failure == 0    
| summarize Failures=count() by Vendor
Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
irom
  • 3,316
  • 14
  • 54
  • 86

2 Answers2

17

Please check if next query solves your scenario:

datatable (Vendor:string, failure:int)
    ["Vendor1",3,
    "Vendor2",0,
    "Vendor2",0,
    "Vendor2", 7,
    "Vendor1",0,
    "Vendor2", 1]   
| summarize Failures=countif(failure == 0), Total=count() by Vendor
| extend Result=Failures*1.0/Total
Alexander Sloutsky
  • 2,827
  • 8
  • 13
6

A slight variation of @Alexander Sloutsky's answer:

datatable (Vendor:string, failure:int)
    ["Vendor1",3,
    "Vendor2",0,
    "Vendor2",0,
    "Vendor2", 7,
    "Vendor1",0,
    "Vendor2", 1]   
| summarize Result = 1.0*countif(failure==0)/count() by Vendor

Demo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275