{"id":4745,"date":"2021-08-26T16:44:20","date_gmt":"2021-08-26T14:44:20","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=4745"},"modified":"2021-08-26T16:44:22","modified_gmt":"2021-08-26T14:44:22","slug":"compare-the-current-counter-value-with-previous-one","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=4745","title":{"rendered":"Compare the current counter value with previous one"},"content":{"rendered":"\n<p>Today I received a question about comparing a performance counter value with the previous performance counter value. In the example, we look at free space on C and compare the current value with the previous. As there are few examples in the community, I thought this would be a good example to share. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Perf\r\n| where Computer == \"idala\"\r\n| where CounterName == \"% Free Space\"\r\n| where InstanceName == \"C:\"\r\n| serialize | extend prevValue = prev(CounterValue, 1)\r\n| extend diffvalue = CounterValue - prevValue\r\n| extend trend = case(CounterValue &lt; prevValue, \"Free Space Reduces\",\r\n                      CounterValue > prevValue, \"Free Space Increases\",\r\n                    \"No difference\")\r\n| project TimeGenerated, InstanceName, CounterValue, prevValue, diffvalue, trend \r\n| order by TimeGenerated desc <\/code><\/pre>\n\n\n\n<p>First, we filter on a computer, counter name, and instance name. Before we can use Window functions on the result, we need to SERIALIZE it. SERIALIZE will freeze the result; in other words, freeze the order on the rows. <\/p>\n\n\n\n<p>We use  EXTEND to create a new column and assign it the value of the previous counterValue. &#8220;1&#8221; after CounterValue means we look on the 1 previous row; this is possible to do as we have a serialized set of rows. <\/p>\n\n\n\n<p>We then use  EXTEND to create a new column that will hold the difference (diffvalue) between the current counter value and the previous counter value. <\/p>\n\n\n\n<p>Even if it is simple to see if the value has reduced or increased manually, we use CASE, and another EXTEND to write different text strings in a column depending on the current counter value and previous counter value.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I received a question about comparing a performance counter value with the previous performance counter value. In the example, we look at free space on C and compare the current value with the previous. As there are few examples in the community, I thought this would be a good example to share. First, we &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=4745\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":4746,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[64,75,71],"tags":[77,72,97,74,76,98],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4745"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4745"}],"version-history":[{"count":1,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4745\/revisions"}],"predecessor-version":[{"id":4747,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4745\/revisions\/4747"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/media\/4746"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4745"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}