如何获取mdx中相同成员的数量?

时间:2015-09-07 08:09:37

标签: sql mdx cube olap-cube

我想确定两个日期之间特定工作日的数量(例如星期一,星期二等......)。我认为以下内容应该有效,但成员返回1.

我做错了什么?

WITH 
  MEMBER measures.NumberOfSameWeekDays AS 
    Count([Dim Date].[Day Of Week].CurrentMember) 
SELECT 
  measures.NumberOfSameWeekDays ON COLUMNS
 ,[Dim Date].[Day Of Week].[Day Of Week] ON ROWS
FROM [test]
WHERE 
  (
    [Dim Client].[Common Client UID].&[{ED8822E7-2873-4388-BC3A-CC553D939FC4}]
   ,
    [Dim Date].[Date Int].&[20150701] : [Dim Date].[Date Int].&[20150731]
  );

2 个答案:

答案 0 :(得分:1)

这是发生了什么的证据:

WITH 
  MEMBER measures.NumberOfSameWeekDays AS 
    Count
    (
      (EXISTING 
        [Date].[Day of Week].CurrentMember * [Date].[Calendar].[Date])
    ) 
SELECT 
  {
    measures.NumberOfSameWeekDays
  } ON COLUMNS
 ,[Date].[Day of Week].[Day of Week] ON ROWS
FROM [Adventure Works]
WHERE 
    [Date].[Calendar].[Date].&[20050101]
  : 
    [Date].[Calendar].[Date].&[20050131];

以上结果如下:

enter image description here

以下是上述行为的解决方案:

WITH 
  MEMBER Measures.CountOfDays AS 
    Generate
    (
      (EXISTING 
        [Date].[Date].[Date].MEMBERS)
     ,[Date].[Day of Week]
     ,ALL
    ).Count 
SELECT 
  Measures.CountOfDays ON 0
 ,[Date].[Day of Week].[Day of Week].MEMBERS ON 1
FROM [Adventure Works]
WHERE 
  [Date].[Calendar].&[2005] : [Date].[Calendar].&[2006];

返回以下内容:

enter image description here

Sourav的答案的简化版本 - 虽然仍然相当复杂 - 并且可能因为使用迭代的Generate而变慢:

$users = Search-ADAccount -AccountInactive -TimeSpan (New-TimeSpan -Days 40) -Searchbase "OU=Users,OU=State,DC=Company,DC=Biz" |
         where {$_.Enabled -eq "True"} |
         Get-ADUser -Properties mail, givenname, surname, manager, lastlogontimestamp, sAMAccountName, description

#Loop through the query results
foreach ($User in $Users) {
  #Convert LastLogonDate to days since last use
  $LLTS = $User.lastLogonTimeStamp
  if ($LLTS -eq $Null) {
    $Time = [Int64]0
  } else {
    $Time = [Int64]::Parse($LLTS)
  }

  $Daysinactive = ($(Get-Date) - $([DateTime]::FromFileTime($Time)).Days)

  #Retrieve $User.Manager email address with Get-Aduser passthrough
  $Manager = Get-ADUser $User.Manager -Properties EmailAddress

  #Set dynamic variables and body of email
  $To = $Manager.EmailAddress
  $Subject = "Your employee $($User.Givenname) $($User.Surname) has been inactive for $Daysinactive ."

  #Send email
  Send-MailMessage -To $To -From $From -Subject $Subject -SmtpServer $SMTPServer -Body $Body -BodyAsHtml -Priority High
}

答案 1 :(得分:1)

Adventure Works版本:

WITH MEMBER Measures.CountOfDays  AS
GENERATE
    (
     EXISTING [Date].[Date].[Date].MEMBERS,
     EXISTING [Date].[Day of Week].[Day of Week].MEMBERS
     ,ALL
    ).COUNT


SELECT Measures.CountOfDays ON 0
,[Date].[Day of Week].[Day of Week].MEMBERS ON 1
FROM [Adventure Works]  
WHERE [Date].[Calendar].&[2005]: [Date].[Calendar].&[2006]

GENERATE部分在当前上下文中基于您可能拥有的任何过滤器获取数周的所有日期。