get current status instead timerange - azure

in Azure workbooks with the below query I am able to get avg of 2 columns a as per time range selected but here least time we can select is 30 mins we have a requirement to show last 1 min status of the result for that I need another column and show last 1 mins status
let start = {TimeRange:start};
let grain = {TimeRange:grain};
workspace(name).site1_CL
| extend healty=iff(Status_s == 'Connected' , 100 , 0)
| summarize table1= avg(healty) by ClientName_s
|join
(workspace(name).site2_CL
| extend Availability=iff(StatusDescription_s == 'OK' , 100 , 0)
|summarize table2=avg(Availability) by ClientName_s
)
on ClientName_s
| extend HealthStatus=(table1+table2)/2
| project Client=ClientName_s,Environment=EnvName_s,HealthStatus
req another column and show current status instead aggregation of selected timerange this column should override selected timerange and show last 1 minute aggregation of 2 tables

CouldnĀ“t you just set the start to use the value you need?
let start = now(-1m); //last minute

Related

Kusto: make-series stops with first day - doesnt work as expected

I am using azure customer metrics to store application usage metrics, I am exporting the stats every 5 minutes. I am using the query below to create a aggregated series without any gaps.
I expect the start to be 5/10/2020, 12:00:00.000 AM and end to be 5/14/2020, 12:00:00.000 AM. However in my results, start is fine , but the end is 5/10/2020, 10:35:00.000 AM. I am running this query on 5/13/2020, 4:09:07.878 AM. The min timestamp in my data is 5/11/2020, 12:54:06.489 PM and max is 5/12/2020, 2:32:47.459 PM.
What is wrong with my query? why the make-series wouldn't give rows beyond day 1
let start = floor(ago(1d),1d);
let end = floor(now(+1d),1d);
customMetrics
| where timestamp >= start
| where name == "endpoint_access_count_count_view"
| extend customMetric_valueSum = iif(itemType == 'customMetric',valueSum,todouble(''))
| make-series n_req = sum(customMetric_valueSum) on timestamp from start to end step 5m
| mvexpand n_req,timestamp
| extend timestamp=todatetime(timestamp),n_req=toint(n_req)
mvexpand, unlike mv-expand (note the hyphen), has a default limit of 128 values, so your results get truncated.
https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/mvexpandoperator

Concatenate column values into a new column based off value in another column

I have a dataframe with the following format:
Item Balance Date
1 200000 1/1/2020
1 155000 2/1/2020
1 100000 3/1/2020
1 25000 4/1/2020
1 0 5/1/2020
2 100000 1/1/2020
2 15000 2/1/2020
2 0 3/1/2020
I would like to change the dataframe to the following format:
Item Cycle
1 4;2#01/01/2020;1000#02/01/2020;775#03/01/2020;500#04/01/2020;125#05/01/2020;0
2 2;2#01/01/2020;1000#02/01/2020;150#03/01/2020;0
The cycle column will take the form of the count of non zero values (Balance field) for each item (there are 4 for item 1 and 2 for item 2) followed by a ; a constant of 2 followed by a # the date in the date column with an initial scaled value of 1000. Then # + (the next date value) + (current balance of item / initial balance of item) * initial scaled balance (1000) until the item observation reaches a balance of 0. When the item balance is 0; the cycle variable will close with #(date in date column);0. Please also note that the date will take the form of mm/dd/yyyy inside the cycle variable.
Thanks in advance for the help.
Assuming your Date column is already converted to datetime64:
def summarize(group):
# The number of line items where Balance > 0
count = (group['Balance'] > 0).sum()
# Scale the data where the initial balance = 1000
scaled = pd.DataFrame({
'Balance': group['Balance'] / group['Balance'].iloc[0] * 1000,
'Date': group['Date'].dt.strftime('%m/%d/%Y')
})
# The lambda to produce the string 01/01/2020;1000
f = lambda row: f'{row["Date"]};{row["Balance"]:.0f}'
# Join the balances togather
data = '#'.join(scaled.apply(f, axis=1))
# The final string for each group
return f'{count};2#{data}'
df.groupby('Item').apply(summarize)

How to "Group By" by result and count in Azure App Insights

I'm trying to group some results I have in app insights and am struggling
If I were to tabulate my results, it would look like
Product Version
A 1
B 2
A 2
A 1
B 3
B 3
As you can see, I have 2 products (A and B), and each has a version number.
I am trying to group these and provide a count, so my end result is
Product Version Count
A 1 2
A 2 1
B 2 1
B 3 2
At the moment, my approach is a mess because I am doing this manually with
customEvents
| summarise A1 = count(customEvents.['payload.prod'] == "A" and myEvents.['payload.vers'] == "1"),
| summarise A2 = count(customEvents.['payload.prod'] == "A" and myEvents.['payload.vers'] == "2")
I have no idea how I can aggregate these so it can group by product and version and then count the occurrences of each
I think your are looking for:
customEvents
| extend Product = tostring(customDimensions.prod)
| extend MajorVersion = split(customDimensions.Version, ".")[0]
| summarize Count = count() by Product , tostring(MajorVersion)
I wrote this off the top off my head so there might be some syntax issues. I assumed prod and vers are in the customdimensions, let me know if it is otherwise.
You can summarize by multiple fields as you can see.

Generate new table from a current table in excel

I have sample table like this:
ID | 1 | 2 | 3
-------------
1 | 0 | 1 | 0
--------------
2 | 1 | 1 | 1
Then I want to generate a new table from that table. It will take the second row (1) then compare with each column (1, 2, 3) then print value of the matrix ( 0 - 1 - 0 ). For example:
Row_ID | Column_ID | Value
--------------------------
1 | 1 | 0
--------------------------
1 | 2 | 1
--------------------------
1 | 3 | 0
--------------------------
2 | 1 | 1
--------------------------
2 | 2 | 1
--------------------------
2 | 3 | 1
I'm not sure how or where to start by using formula. Please help. Thanks,
Well. There's no single formula that's going to do the job, obviously, but we have a few options we can use. I'll assume that the new table is going to start in cell A1 of Sheet2. Adjust accordingly.
Start with manually entered headers
Row_ID | Column_ID | Value
In the first column, first row, enter a 1. In rows below, use this formula: =IF(B3<B2,A2+1,A2) This will increment the value in the first column by 1 each time the second column resets its numbering.
In the second column, first row, enter a 1. The formula we'll use for this one will need some tweaking, but the basic version is: =IF(MOD(ROW()**+1**,**3**)=0,1,B2+1)
This formula is going to essentially count up to a certain point, then reset its numbering. The point it will count to, and where it will reset, will vary depending on the amount of data you have and which row you're starting from. Replace the 3 with the number of data columns you have, and remove the **s. The +1 is needed to increase the Row() counter to the SAME NUMBER as your number of data columns. So in my example, with 3 data columns and starting on row 2, the ROW() function gives us 2, so we need to add 1 to that to get up to a total of 3. If I had 5 data columns, I would add 3 to the total. Hope that makes sense.
These two formulae should give you a set of row and column numbers. Copying the formula down will force the values to increase as needed, thus:
Row_ID | Column_ID | Value
1 | 1 |
1 | 2 |
1 | 3 |
2 | 1 |
...etc.
Finally, to bring in the values, we'll use an OFFSET formula in the Value column: =OFFSET(Sheet1!$A$1,A2,B2) That formula starts from a reference cell - A1, in this case - then moves down x number of rows and across y number of columns to return a value. X and Y are provided by the formulas we already have. Your final structure will be something like this:
Row_ID | Column_ID | Value
1 | 1 |=OFFSET(...
=IF(...|=IF(MOD(...|=OFFSET(...
I hope all that made sense. Please let me know if there's anything that doesn't, and I'll try to troubleshoot.
EDITED TO ADD:
If the Row ID is something like a key that needs to be included with each value, we can get that fairly easily. We'll include another column with a slightly modified OFFSET formula: =OFFSET(Sheet1!$A$1,A2,0)
With this version of the formula we're not changing the column as we go down, just the row when it changes. It allows the values in the first row to be repeated in every row of the table. So this is my input:
And this is my output:
Notice that the ID repeats on each line of the output for the same item.

Get Sum Of Columns Values Filtered Based On Another Columns Date

I have a spreadsheet that basicly have several hundred rows that look like this
|01-Jan-16 (Fri) | Work | 0 | 0 | 3 | 0 | 9 | 7 | 0 | 0 |
I have been trying to generate a query that will calculate the total of each of the columns during any given quarter. So it will essentially select all the dates for month 1-3, 4-6, 7-9, 10-12 and calculates the total of value in all the 8 columns.
I have tried sumsif, and sumproduct but I can't get it to work, I am currently playing around with
=SUMPRODUCT( (MONTH('2016'!$A4:$A999)=1) * (MONTH('2016'!$A4:$A999)=2) * (MONTH('2016'!$A4:$A999)=3) * ('2016'!$C4:$C999) )
=SUMIFS('2016'!C4:C999, '2016'!A4:A999, "<=3", '2016'!A4:A999, ">=1")
=SUMPRODUCT((MONTH('2016'!$A4:$A999)>=1)*(MONTH('2016'!$A4:$A999)<=3)*('2016'!B4:B999))
This worked for me.
=SUMPRODUCT( (MONTH('2016'!$A4:$A999)=1) * (MONTH('2016'!$A4:$A999)=2) * (MONTH('2016'!$A4:$A999)=3) * ('2016'!$C4:$C999) )
The date field is not a date value but a string so that is what is causing the problem. To get it to work you will need to pull out the date value for the match. I tested this with data created based off your example and it worked.
=SUMPRODUCT((MONTH(DATEVALUE(MID(A2:A5,1,9)))<=3)*(C2:J5))

Resources