How to extract median by using Kusto - metrics

I figured out, that i need the percentiles function to extract the median. Still, i don't really get a result. I want to find out how many mails are filed on average without the outlier distorting the result. The customDimensions.AmountStored contains the information about how many mails got stored.
I'm using this query:
AllShards_CustomEvents
| where name == "Mail.Implementation.StoreCount"
| extend storeCount = toint(customDimensions.AmountStored)
| project timestamp, shard=tostring(customDimensions.ShardName), storeCount
| summarize percentiles(storeCount, 5, 50, 95) by bin(timestamp, 7d), shard

Perhaps, I am missing something - but the query below seems to be working fine.
Perhaps, you can clarify what exactly is not working for you?
let AllShards_CustomEvents = datatable(timestamp:datetime, name:string, customDimensions:dynamic)
[
datetime(2020-03-30 16:55), "Mail.Implementation.StoreCount", dynamic({'AmountStored': 100}),
datetime(2020-03-30 16:57), "Mail.Implementation.StoreCount", dynamic({'AmountStored': 200}),
datetime(2020-03-30 16:57), "Mail.Implementation.StoreCount", dynamic({'AmountStored': 300}),
datetime(2020-03-30 16:57), "Mail.Implementation.StoreCount", dynamic({'AmountStored': 400}),
datetime(2020-03-30 16:57), "Mail.Implementation.StoreCount", dynamic({'AmountStored': 500}),
];
AllShards_CustomEvents
| where name == "Mail.Implementation.StoreCount"
| extend storeCount = toint(customDimensions.AmountStored)
| project timestamp, shard=tostring(customDimensions.ShardName), storeCount
| summarize percentiles(storeCount, 5, 50, 95) by bin(timestamp, 7d), shard
|timestamp|shard|percentile_storeCount_5|percentile_storeCount_50|percentile_storeCount_95|
|---|---|---|---|---|
|2020-03-30 00:00:00.0000000||100|300|500|

Related

Hive - rlike not returning results meeting multiple conditions

I'm looking to return encounters later than 12-17-2020 for each patient involving any of the antibiotics. I'm expecting many results, as querying by one antibiotic at a time shows me. But when I string them together in rlike, it only returns results for one patient for the first antibiotic, amikacin. Is there something wrong in the syntax?
CREATE TABLE tsri.antibiotics AS
SELECT * FROM observation_fact_meds
WHERE start_date > "2020-12-17"
AND encounter_num in (select distinct encounter_num from visit_dimension where patient_num in ('000000', '000001', '000002', '000003', '000004', '000006', '000007') and INOUT_CD in ('Inpatient'))
AND DESCRIPTION rlike ('amikacin| amoxicillin| amoxicillin-clavulanate| Amphotericin B| ampicillin| ampicillin-sulbactam | azithromycin| aztreonam| bacitracin| cefazolin | efepime | cefiderocol| cefotaxime | cefoxitin| ceftaroline| ceftazidime | ceftazidime-avibactam| ceftriaxone | cefuroxime | cephalexin| ciprofloxacin| clarithromycin| clindamycin | Cloxacillin| Cotrimoxazole | dapsone| erythromycin| gentamicin| imipenem| imipenem-cilastatin| isoniazid| lefamulin| levofloxacin| linezolid| meropenem| metronidazole| Nafcillin| Nystatin| penicillin| pentamidine| piperacillin-tazobactam| Piperacillin | rifampin | sulfamethoxazole-trimethoprim | TNF Antimicrobial Med| tobramycin| vancomycin')
Remove the space before pattern - pls put exact string you are looking for a string seperate them only by pipe.
DESCRIPTION rlike ('amikacin|amoxicillin|...

Solana - Commitment vs preflightCommitment

I'm curious what the difference between preflightCommitment and commitment is.
Also, what are the different types of commitments listed below.
export type Commitment =
| 'processed'
| 'confirmed'
| 'finalized'
| 'recent'
| 'single'
| 'singleGossip'
| 'root'
| 'max';
preflightCommitment is the commitment used for the preflight transaction, AKA the transaction simulation, whereas commitment is used for the actual transaction.
As for the different commitments, they're all listed at https://docs.solana.com/developing/clients/jsonrpc-api#configuring-state-commitment
Some of those terms are old, but here's roughly how they would translate:
processed = recent
confirmed = singleGossip = single
finalized = root = max

how to use List.Generate as a loop

This might be simple but would appreciate any help to push me in the right direction. I am trying to use the list.generate in power query to count number of tix based on the difference from 1-5. It is a must that a loop is used such as the list.generate.
current tix-1
current tix-2
current tix-3
current tix-4
current tix-5
= Table.AddColumn(#"Added Custom1", "Count", each List.Count(Table.SelectRows(#"Added Custom1", (C) =>
(
[Tix]=C[Tix]-(List.Generate(()=>1,each _ 5, each _ - 1))
)
)[Column1]))
Here is the sample data. The idea is for me to able to put in the generated series of number as a loop. this is the simplest representation because for other formula, I need the generated number as the x eg. (-1/2 x*x + 41/2 x).
+-------------+------------+
TIX |TIX count |
5,000,243 | 0 |
6,991,904 | 0 |
6,991,905 | 1 |
6,991,906 | 2 |
6,991,907 | 3 |
6,991,908 | 4 |
7,000,234 | 0 |
+-------------+------------+
To simply put my targeted code should be something like this which i believe could be simplify by list.generate.
= Table.AddColumn(#"Added Custom1", "Count", each List.Count(Table.SelectRows(#"Added Custom1", (C) =>
(
[Tix]=C[Tix]-1
+[Tix]=C[Tix]-2
+[Tix]=C[Tix]-3
+[Tix]=C[Tix]-4
+[Tix]=C[Tix]-5 )
)
)[Column1]))
Tried another code based on almost similar post : Power Query M loop table / lookup via a self-join.
This also returns an error. Please advise what I'm doing wrong.
= Table.AddColumn(
#"Renamed Columns",
"Count",
List.Sum(
List.Generate(
() => [Continue = 1],
each [Continue]<6,
each [Count =
List.Count(
Table.SelectRows(
#"Renamed Columns",
(x) => x[Tix]-[Continue]= [Tix]))[Column1]],
each [Count])))
thru research, i found the solution:
= Table.AddColumn(#"Added Custom2", 
"Count", each List.Sum(
List.Generate(
() => [Count=List.Count(Table.SelectRows(#"Added Custom2",
(C) => C[Tix] = [Tix]-Continue)
[Column1]),
Continue =1],
each [Continue]<=10,
each [Final_Item = [Final_Item], 
Continue =[Continue]+1],
each [Count])))

How to get last month record from databse in laravel?

i have a table remaining_bus_fees.
id | date | student_id | remaining_balance
-----------------------------------------------------
1 | 2019-04-05 | 1 | 500
2 | 2019-05-10 | 2 | 400
3 | 2019-05-13 | 3 | 300
Now i need how to get last month record against student_id. here is
query i am using. but this is not working for me.
$remain_fee = \DB::table('remaining_bus_fees')
->whereMonth('date', '<', Carbon::now()->subMonth()->month)
->where('student_id', '=', 2)->get();
Here is useful queries :
$today=DB::table('remaining_bus_fees')->whereRaw('Date(created_at) = CURDATE()')->where('student_id', 2)->get();
$yesterday= DB::table('remaining_bus_fees')->whereDate('created_at',Carbon::yesterday())->get();
$last_7_days= DB::table('remaining_bus_fees')->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get();
$this_month=DB::table('remaining_bus_fees')->whereMonth('created_at',Carbon::now()->month)->whereYear('created_at', date('Y'))->where('student_id', 2)->get();
$last_month=DB::table('remaining_bus_fees')->whereMonth('created_at',Carbon::now()->subMonth()->format('m'))->whereYear('created_at', date('Y'))->where('student_id', 2)->get();
Change your code to this and it should work fine, you need to convert your Carbon::now() to date format as you will use whereDate here, it will consider only date.
$remain_fee = \DB::table('remaining_bus_fees')
->whereDate('date', '<', Carbon::now()->subMonth()->toDateString())
->where('student_id', '=', 2)->get();
Example in tinker
>>> App\User::whereDate('created_at', Carbon\Carbon::now()->subMonth()->toDateSt
ring())->get()
=> Illuminate\Database\Eloquent\Collection {#3120
all: [
App\User {#3114
id: 90,
name: "******",
email: "******#gmail.com",
created_at: "2019-05-01 06:17:47",
updated_at: "2019-05-02 00:28:18",
},
],
}
>>>
Try this out,
$remain_fee = \DB::table('remaining_bus_fees')
->whereMonth('date', '=', Carbon::now()->subMonth()->month)
->whereStudentId(2)->get();
At the minute your code is saying where date is "before a month ago" whereas it should be where the date is a month ago (i.e. remove <). Also, I would suggest adding the year to the query as well otherwise you'll start to get previous years results.
This should get you what you need:
$date = Carbon::now()->subMonth();
$remain_fee = \DB::table('remaining_bus_fees')
->whereMonth('date', $date->month)
->whereYear('date', $date->year)
->where('student_id', 2)
->get();

How to duplicate Sum(Sum(Fields!VarName.Value)) using Lookupsets and Custom Code in SSRS

I am fairly new to SSRS but am having a problem double summing when using Lookupsets as output. I have the following table and query which does work
Query for Hours_DataSet
SELECT CallbackDate, SUM(TelemarketingHours) AS DailyHours,
(SELECT SUM(TelemarketingHours) AS Expr1
FROM CallbackTbl) AS HoursPTD
FROM CallbackTbl AS CallbackTbl_1
GROUP BY CallbackDate
Definition of Matrix
| [CallbackDate] | Weekly totals
________________________________________________________________
Hours | [Sum(DailyHours]) | Sum(Sum(DailyHours))
The output is this:
12/01/2014 | 12/02/2014 | 12/03/2014 | 12/04/2014 | 12/05/2014| Weekly totals|
28.75 | 42 | 42.25 | 40.25 | 37.50 | 190.75
In another table I need to calculate the appointments per hour and total appointments per hour for the week. So I set the main data-set to be the number of appointments and use lookupset and custom code to do the summing.
Everything works well for one level of sum. I need to recreate the 190.75 number and use it in the as the denominator in the calculation for number of appointments per hour for the week.
Query for Positive_DataSet:
SELECT MainHistory_1.REALDATE, StatusTbl.Status, COUNT (MainHistory_1.DBRECID) AS Positives, StatusTbl.Code,
(SELECT COUNT(DBRECID) AS Expr1
FROM MainHistory
WHERE (REALDATE > CONVERT(DATETIME, #StartDate, 102)) AND (REALDATE < CONVERT(DATETIME, #EndDate, 102))) AS TotalCalls
FROM MainHistory AS MainHistory_1 INNER JOIN
StatusTbl ON MainHistory_1.STATUS = StatusTbl.Status
GROUP BY MainHistory_1.REALDATE, StatusTbl.Status, StatusTbl.Code
HAVING (StatusTbl.Code = 'P') AND (MainHistory_1.REALDATE > CONVERT(DATETIME, #StartDate, 102)) AND (MainHistory_1.REALDATE < CONVERT(DATETIME, #EndDate, 102))
My Matrix looks like this:
[REALDATE]| Weekly Totals
EXPR | EXPR
where the expressions are
FORMAT(Code.CalcPerHour(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet"),SUM(Fields!Positives.Value)),"Fixed")
Sum(Sum(Fields!Positives.Value))/SUM(code.CalcPTD(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet")))
My custom code is this:
PUBLIC SHARED FUNCTION CalcPerHour(Hours AS OBJECT, Totals AS OBJECT) AS DECIMAL
DIM i AS INTEGER
DIM PerHour AS DECIMAL
FOR i=0 TO UBOUND(Hours)
IF CINT(Hours(i)) < > 0 THEN
PerHour = PerHour + (CDEC(Totals)/CDEC(Hours(i)))
END IF
Next i
RETURN PerHour
END FUNCTION
PUBLIC SHARED FUNCTION CalcPTD(LookupArray AS Array) AS DECIMAL
DIM I AS INTEGER
DIM Total AS DECIMAL
Total = 0
FOR i = 0 to UBOUND(LookupArray)
Total = Total + CDEC(LookupArray(i))
NEXT i
RETURN Total
END FUNCTION
My Output is this:
12/01/2014 | 12/02/2014 | 12/03/2014 | 12/04/2014 | 12/05/2014 | Weekly totals|
1.63 | 1.79 | 1.75 | 1.59 | 1.41 | .87
The numbers corresponding to the days of the week are correct.
The number I should be getting for a total is
313/190.75 = 1.64
If I break it down and just look at the sum like this:
sum(Code.CalcPTD(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet")))
I get the result of 352.50
If I count the number of items like this:
Count(Code.CalcPTD(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMA(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet")))
I get the result of 9
If I count distinct the number of items like this:
CountDistinct(Code.CalcPTD(Lookupset(FORMAT(Fields!REALDATE.Value,"Long Date"),FORMAT(Fields!CallbackDate.Value,"Long Date"),Fields!DailyHours.Value,"Hours_DataSet")))
I get the expected 5
I tried to write code for a distinct sum but it wouldn't return a single result but a series of 5 corresponding to the days of the week and I have to display in a single cell.
Any help would be appreciated. I know its kinda complicated. If you have questions or need further clarification please let me know.
So I figured out the answer on my own. To get a grand total of a variable within a dataset you can use SUM(fields!VarName.Value,"DataSet") and it does it for you.

Resources