透视应用程序见解后的列顺序

时间:2018-08-20 20:11:47

标签: azure-application-insights

用户希望每周获得一次有关应用数据洞察的不重复会话数。我的查询工作正常,包括数据透视,但“周”列不正常。我希望它们是否有秩序。

pageViews
| where timestamp < now() 
| summarize Sessions= dcount(session_Id)
  by Week=bin(datepart("weekOfYear", timestamp), 1), user_AuthenticatedId
| order by Week
| evaluate pivot(Week, sum(Sessions))
| join kind=innerunique (pageViews
                      | summarize MostRecentRequest =    max(timestamp)  by user_AuthenticatedId) 
                      on $right.user_AuthenticatedId == $left.user_AuthenticatedId
| project-away user_AuthenticatedId1

我尝试在摘要之前按时间戳排序,并在摘要之后按周排序(仍然在那里),但是没有运气。

2 个答案:

答案 0 :(得分:1)

当前有一个“技巧”可以使用:serialize之后的order by

pageViews
| where timestamp < now()
| where isnotempty(user_AuthenticatedId)
| summarize Sessions= dcount(session_Id)
  by Week=bin(datepart("weekOfYear", timestamp), 1), user_AuthenticatedId
| order by Week
| serialize // <--------------------------------- RIGHT HERE
| evaluate pivot(Week, sum(Sessions))
| join kind=innerunique (pageViews
| summarize TotalSessions=dcount(session_Id), MostRecentRequest = max(timestamp) by user_AuthenticatedId) 
on $right.user_AuthenticatedId == $left.user_AuthenticatedId
| project-away user_AuthenticatedId1
| top 100 by TotalSessions desc

在工作簿中得到此信息,星期以降序排列(我还通过设置一些自定义列设置将总会话数添加到排序/排行中):

workbook with heatmap

工作簿中列设置的自定义设置: 删除默认情况下存在的所有#列,并为设置为热图的^[0-9]+$添加一列: column settings

答案 1 :(得分:0)

我对自己的理解力做了一些重构。我把左边和右边变成“视图”。以为我会分享。

let users_MostRecent_Session = 
    pageViews
    | summarize 
        TotalSessions=dcount(session_Id)
        , MostRecentRequest = max(timestamp)  
        by 
        user_AuthenticatedId
;
//
let users_sessions_ByWeek = 
    pageViews
    | where timestamp < now() 
    | where isnotempty(user_AuthenticatedId)
    | summarize 
        Sessions= dcount(session_Id)
        by 
        Week=bin(datepart("weekOfYear", timestamp), 1)
        , user_AuthenticatedId
    | order by Week
    | serialize 
    | evaluate pivot(Week, sum(Sessions))
;
//
//
users_sessions_ByWeek
| join  kind=innerunique 
        users_MostRecent_Session 
        on user_AuthenticatedId
| project-away user_AuthenticatedId1
| top 100 by TotalSessions desc