在 Application Insights 中获取月份的名称
Get the name of a month in Application Insights
我是应用程序见解的新手,我正在编写一个查询以从 Azure 中提取少量数据。我需要获取月份的名称。我尝试了下面的查询,但我在输出中得到的只是数值 1。
我需要将值作为字符串放在单独的列中,例如 "January"、"February"。 下面是输出快照:
我写的查询:
customEvents | summarize Count = dcount(cloud_RoleInstance) by ProductVersion = tostring(customDimensions.["Version"]), Month = monthofyear(timestamp)
任何建议都会非常有帮助。谢谢
没有内置函数。所以你应该定义一个user-defined function来实现这个。
示例代码如下,您可以根据自己的需要进行修改:
let f=(a:int){
case(a==1,"Jan",
a==2,"Feb",
a==3,"Mar",
//add the other month
a==12,"Dec",
"Error"
)
};
traces
| summarize count() by cloud_RoleName ,Month=f(getmonth(timestamp))
测试结果:
这里是针对您的情况的查询,请在函数中添加其他月份。
let f=(a:int){
case(a==1,"Jan",
a==2,"Feb",
a==3,"Mar",
//add the other month
a==12,"Dec",
"Error"
)
};
customEvents
| summarize Count = dcount(cloud_RoleInstance) by ProductVersion = tostring(customDimensions.["Version"]), Month = f(getmonth(timestamp))
我是应用程序见解的新手,我正在编写一个查询以从 Azure 中提取少量数据。我需要获取月份的名称。我尝试了下面的查询,但我在输出中得到的只是数值 1。 我需要将值作为字符串放在单独的列中,例如 "January"、"February"。 下面是输出快照:
我写的查询:
customEvents | summarize Count = dcount(cloud_RoleInstance) by ProductVersion = tostring(customDimensions.["Version"]), Month = monthofyear(timestamp)
任何建议都会非常有帮助。谢谢
没有内置函数。所以你应该定义一个user-defined function来实现这个。
示例代码如下,您可以根据自己的需要进行修改:
let f=(a:int){
case(a==1,"Jan",
a==2,"Feb",
a==3,"Mar",
//add the other month
a==12,"Dec",
"Error"
)
};
traces
| summarize count() by cloud_RoleName ,Month=f(getmonth(timestamp))
测试结果:
这里是针对您的情况的查询,请在函数中添加其他月份。
let f=(a:int){
case(a==1,"Jan",
a==2,"Feb",
a==3,"Mar",
//add the other month
a==12,"Dec",
"Error"
)
};
customEvents
| summarize Count = dcount(cloud_RoleInstance) by ProductVersion = tostring(customDimensions.["Version"]), Month = f(getmonth(timestamp))