'how to get te avarege of values in a table

Im trying to get some information out of log analytcs and I want to know if I can extract the avarege of values fron different lines for exemple, lets say I have a table that goes like this:

.create table custumer (name: string, month: int, salary: long, living: long)
.ingest inline into table customer<
gabriel, 1, 1000, 500
gabriel, 2, 1000, 800 
gabriel, 3, 2500, 800
gabriel, 4, 2500, 800
John, 1, 1500, 1000
John, 2, 1500, 500
John, 3, 1500, 500
John, 4, 1500, 1200
jina, 1, 3000, 1000
jina, 2, 3000, 1000
jina, 3, 3000, 1500
jina, 4, 5000, 2500

here we have the simplest possible table to explain my inquire, we're listing the salary and living expenses of each custumer per month (namely month 1, month 2, 3 and 4) Then I want to kow the avarege salary and living expenses of gabriel, John and Jina in this period of 4 months the actual query I want to aply this is a tad more complicated but this is enogh to explain my problem

kql


Solution 1:[1]

I think this is what you are looking for:

datatable(name:string, month:int, salary:long, living:long)[
'gabriel', 1, 1000, 500,
'gabriel', 2, 1000, 800,
'gabriel', 3, 2500, 800,
'gabriel', 4, 2500, 800,
'John', 1, 1500, 1000,
'John', 2, 1500, 500,
'John', 3, 1500, 500,
'John', 4, 1500, 1200,
'jina', 1, 3000, 1000,
'jina', 2, 3000, 1000,
'jina', 3, 3000, 1500,
'jina', 4, 5000, 2500]
| summarize Avg_Salary=avg(salary), Avg_Expenses=avg(living) by name

Result:

name     Avg_Salary  Avg_Expenses
gabriel  1750        725
John     1500        800
jina     3500        1500

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PorgtheEaten