【问题标题】:Order of columns after pivot in application insights应用洞察中数据透视后的列顺序
【发布时间】:2018-08-20 20:11:46
【问题描述】:

用户希望在应用洞察中计算每周的唯一会话数。我的查询正常工作,包括一个数据透视表,但 Week 列出现故障。如果它们是有序的,我会更喜欢。

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

我尝试在汇总之前按时间戳排序,并在汇总之后按周排序(仍在其中),但没有运气。

【问题讨论】:

    标签: azure-application-insights


    【解决方案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
    

    在工作簿中得到这个,周数按降序排列(我还通过设置一些自定义列设置将总会话数添加到排序/顶部):

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

    【讨论】:

      【解决方案2】:

      为了我自己的理解,我稍微重构了查询。我把左边和右边变成了“视图”。我想我会分享。

      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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-09
        • 1970-01-01
        • 1970-01-01
        • 2021-10-27
        • 1970-01-01
        • 2016-08-26
        • 1970-01-01
        • 2021-02-03
        相关资源
        最近更新 更多