SOLVED

How to have a time chart show zero for missing/null data.

%3CLINGO-SUB%20id%3D%22lingo-sub-124611%22%20slang%3D%22en-US%22%3EHow%20to%20have%20a%20time%20chart%20show%20zero%20for%20missing%2Fnull%20data.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-124611%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20data%20set%20that%20when%20I%20use%20the%20summarize%2Fbin%20over%20a%201%20min%20interval%20has%20gaps%20in%20the%20data%20(hours)%20and%20when%20the%20timechart%20renders%20the%20graph%20the%20line%20goes%20directly%20from%20the%20last%20value%20in%20one%20set%20to%20the%20first%20value%20in%20the%20next%20set%20(so%20it%20looks%20like%20there%20is%20some%20data%20there).%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EIs%20there%20a%20way%20to%20have%20the%20summarize%2Fbin%20function%20or%20the%20timechart%20to%20use%20zero%20(or%20some%20default%20value)%20for%20the%20buckets%20that%20I%20don't%20have%20data%20for%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-thanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-124611%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Log%20Analytics%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-323641%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20have%20a%20time%20chart%20show%20zero%20for%20missing%2Fnull%20data.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-323641%22%20slang%3D%22en-US%22%3EHow%20to%20make%20%22make-series%22%20work%20with%20time%20range%20on%20portal%20instead%20of%20hard%20coding%20the%20value%2Fspecifying%20the%20relative%20time%20range.%3CBR%20%2F%3E%3CBR%20%2F%3Erange(ago(1d)%2C%20now()%2C%201h)%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20I%20change%20the%20time%20range%20from%20portal%20to%20say%20last%207%20days%2C%20how%20to%20make%20it%20work%20with%20%22make-series%22%20without%20editing%20the%20query%20%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-162604%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20have%20a%20time%20chart%20show%20zero%20for%20missing%2Fnull%20data.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-162604%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20just%20saved%20my%20life!%20Both%20issues%20were%20at%20play%20and%20now%20the%20data%20looks%20correct.%20Thank%20you%20so%20much%20Evgeny%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-162456%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20have%20a%20time%20chart%20show%20zero%20for%20missing%2Fnull%20data.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-162456%22%20slang%3D%22en-US%22%3E%3CP%3EWithout%20seeing%20actual%20data%2C%20a%20couple%20of%20possibilities%20come%20to%20mind%20that%20might%20affect%20this%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Emvexpand%20has%20a%20default%20length%20limit%20of%20128%20rows%20that%20can%20be%20overridden%20(details%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.loganalytics.io%2Fdocs%2FLanguage-Reference%2FTabular-operators%2Fmvexpand-operator%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edocs%3C%2FA%3E).%26nbsp%3B%3C%2FLI%3E%0A%3CLI%3Ethe%20range%20limits%20specified%20in%20make-series%20do%20not%20today%20override%20the%20timepicker%20next%20to%20the%20run%20button.%20It's%20possible%20that%20the%20time%20picker%20is%20set%20to%20a%20shorter%20time%20range%20than%20that%20in%20your%20make-series%2C%20resulting%20in%20missing%20data.%20A%20guaranteed%20way%20to%20verify%20this%20is%20by%20parameterizing%20your%20range%3A%3CBR%20%2F%3E%3CPRE%3Elet%20span%20%3D%207d%3B%0APerf%0A%7C%20where%20TimeGenerated%20%26gt%3B%20ago(span)%0A%7C%20where%20CounterName%20%3D%3D%20%22%25%20Processor%20Time%22%20%0A%7C%20make-series%20avg(CounterValue)%20on%20TimeGenerated%20in%20range(ago(span)%2C%20now()%2C%2030m)%20by%20Computer%0A%7C%20mvexpand%20TimeGenerated%20%2C%20avg_CounterValue%20%0A%7C%20project%20TimeGenerated%3Dtodatetime(TimeGenerated)-8h%2C%20Computer%2C%20Hits%20%3D%20toint(avg_CounterValue)%3C%2FPRE%3E%0AAdding%20the%20extra%20%7C%20where%20TimeGenerated...%20clause%20overrides%20the%20time%20picker.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EPlease%20give%20these%20two%20a%20shot%2C%20and%20if%20still%20not%20working%2C%20let%20me%20know%20and%20we%20can%20dig%20deeper.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-162442%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20have%20a%20time%20chart%20show%20zero%20for%20missing%2Fnull%20data.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-162442%22%20slang%3D%22en-US%22%3E%3CP%3Emake-series%20with%20mvexpand%20doesn't%20work%20in%20a%20predictable%20way%20for%20me.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETake%20for%20example%3A%3C%2FP%3E%0A%3CPRE%3EPerf%0A%7C%20where%20CounterName%20%3D%3D%20%22Thread%20Count%22%20%0A%7C%20where%20InstanceName%20%3D%3D%20%22AgentService%22%0A%7C%20make-series%20avg(CounterValue)%20on%20TimeGenerated%20in%20range(ago(1d)%2C%20now()%2C%2030m)%20by%20Computer%0A%7C%20mvexpand%20TimeGenerated%20%2C%20avg_CounterValue%20%0A%7C%20project%20TimeGenerated%3Dtodatetime(TimeGenerated)-8h%2C%20Computer%2C%20Hits%20%3D%20toint(avg_CounterValue)%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt%20will%20return%200%20for%20all%20days%20when%20it%20should%20return%206.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20I%20run%20just%20up%20to%20the%20make-series%20part%20and%20examine%20one%20of%20the%20Computer%20series%2C%20the%20data%20looks%20partially%20correct.%20The%20last%2024%20hours%20for%20a%20given%20computer%20show%206%2C%20everything%20else%20is%200.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20I%20reduce%20the%20range%20from%207d%20to%201d%2C%20the%20data%20looks%20correct.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIs%20there%20something%20wrong%20with%20my%20query%3F%20Is%20there%20some%20limitation%20or%20bug%20I%20am%20running%20into%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-124933%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20have%20a%20time%20chart%20show%20zero%20for%20missing%2Fnull%20data.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-124933%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20check%20out%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.loganalytics.io%2Fdocs%2FLanguage-Reference%2FTabular-operators%2Fmake-series-operator%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emake-series%20%3C%2FA%3Efunction%20to%20achieve%20this.%20For%20example%2C%20instead%20of%20saying%3A%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3EHeartbeat%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E%7C%20where%20TimeGenerated%20%26gt%3B%20ago(1d)%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E%7C%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Esummarize%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Ecount%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E()%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Eby%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3EComputer%2C%20bin(TimeGenerated%2C%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E1%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Eh)%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3EYou%20can%20say%3A%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3EHeartbeat%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E%7C%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Emake-series%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Ecount%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E()%20default%3D%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E0%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Eon%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3ETimeGenerated%20in%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Erange%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E(ago(%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E1%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Ed)%2C%20now()%2C%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E1%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Eh)%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Eby%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3EComputer%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3EThe%20output%20is%20a%20bit%20different%20for%20make-series%20(you%20get%20an%20array%20for%20datetimes%20and%20an%20array%20for%20the%20count%20for%20each%20computer%20rather%20than%20a%20row%20combination%20for%20each)%2C%20so%20if%20you%20want%20the%20data%20in%20the%20same%20format%20that%20summarize%20produces%2C%20you%20can%20do%20so%20via%20%3CA%20href%3D%22https%3A%2F%2Fdocs.loganalytics.io%2Fdocs%2FLanguage-Reference%2FTabular-operators%2Fmvexpand-operator%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Emvexpand%3C%2FA%3E%3A%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3EHeartbeat%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E%7C%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Emake-series%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Ecount%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E()%20default%3D%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E0%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Eon%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3ETimeGenerated%20in%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Erange%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E(ago(%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E1%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Ed)%2C%20now()%2C%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E1%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Eh)%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Eby%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3EComputer%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3E%7C%20%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Emvexpand%3C%2FFONT%3E%3C%2FSPAN%3E%3CSPAN%3E%3CFONT%20face%3D%22Consolas%22%3Ecount_%2C%20TimeGenerated%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-859758%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20have%20a%20time%20chart%20show%20zero%20for%20missing%2Fnull%20data.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-859758%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F68646%22%20target%3D%22_blank%22%3E%40Evgeny%20Ternovsky%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFound%20this%20super%20helpful%20as%20well%20when%20I%20was%20creating%20a%20time-series%20graph%20of%20some%20data%20that%20had%20several%20days%20with%20zero%20values.%26nbsp%3B%20Much%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Deleted
Not applicable

Hi,

 

I have a data set that when I use the summarize/bin over a 1 min interval has gaps in the data (hours) and when the timechart renders the graph the line goes directly from the last value in one set to the first value in the next set (so it looks like there is some data there). 

Is there a way to have the summarize/bin function or the timechart to use zero (or some default value) for the buckets that I don't have data for?

 

-thanks

6 Replies
Highlighted
Solution

Hi,

 

Please check out the make-series function to achieve this. For example, instead of saying:

Heartbeat
| where TimeGenerated > ago(1d)
| summarize count() by Computer, bin(TimeGenerated, 1h)
 

You can say:

Heartbeat
| make-series count() default=0 on TimeGenerated in range(ago(1d), now(), 1h) by Computer
 
The output is a bit different for make-series (you get an array for datetimes and an array for the count for each computer rather than a row combination for each), so if you want the data in the same format that summarize produces, you can do so via mvexpand:
Heartbeat
| make-series count() default=0 on TimeGenerated in range(ago(1d), now(), 1h) by Computer
| mvexpand count_, TimeGenerated
Highlighted

make-series with mvexpand doesn't work in a predictable way for me.

 

Take for example:

Perf
| where CounterName == "Thread Count" 
| where InstanceName == "AgentService"
| make-series avg(CounterValue) on TimeGenerated in range(ago(1d), now(), 30m) by Computer
| mvexpand TimeGenerated , avg_CounterValue 
| project TimeGenerated=todatetime(TimeGenerated)-8h, Computer, Hits = toint(avg_CounterValue)

 

It will return 0 for all days when it should return 6.

 

If I run just up to the make-series part and examine one of the Computer series, the data looks partially correct. The last 24 hours for a given computer show 6, everything else is 0.

 

If I reduce the range from 7d to 1d, the data looks correct.

 

Is there something wrong with my query? Is there some limitation or bug I am running into?

Highlighted

Without seeing actual data, a couple of possibilities come to mind that might affect this:

  • mvexpand has a default length limit of 128 rows that can be overridden (details in docs). 
  • the range limits specified in make-series do not today override the timepicker next to the run button. It's possible that the time picker is set to a shorter time range than that in your make-series, resulting in missing data. A guaranteed way to verify this is by parameterizing your range:
    let span = 7d;
    Perf
    | where TimeGenerated > ago(span)
    | where CounterName == "% Processor Time" 
    | make-series avg(CounterValue) on TimeGenerated in range(ago(span), now(), 30m) by Computer
    | mvexpand TimeGenerated , avg_CounterValue 
    | project TimeGenerated=todatetime(TimeGenerated)-8h, Computer, Hits = toint(avg_CounterValue)
    Adding the extra | where TimeGenerated... clause overrides the time picker.

Please give these two a shot, and if still not working, let me know and we can dig deeper.

Highlighted

You just saved my life! Both issues were at play and now the data looks correct. Thank you so much Evgeny :)

Highlighted
How to make "make-series" work with time range on portal instead of hard coding the value/specifying the relative time range.

range(ago(1d), now(), 1h)

If I change the time range from portal to say last 7 days, how to make it work with "make-series" without editing the query ?
Highlighted

@Evgeny Ternovsky 

Found this super helpful as well when I was creating a time-series graph of some data that had several days with zero values.  Much appreciated.