2016-07-12 5 views
0

Ich versuche, die Zeile mit dem ersten Datum basierend auf den folgenden Daten zu erhalten mit den Filtern, die ich angewendet habe, zu erhalten. Die Abfrage unten hat Duplikate für die "Eltern Vorfall ID" Schlüssel, was ich will, ist das früheste Datum innerhalb der gefilterten Parameter unten für "Geändert von ID" beginnend mit "N" und etc. Danke für jede Hilfe.MDX Eariest Date in einem Satz

SELECT 
NON EMPTY {[Measures].[Count of Assignee Reassignments]} ON COLUMNS, 
NON EMPTY 
    { 
    (
     [Related Assignee History].[Modified By Id].[Modified By Id].ALLMEMBERS 
    *[Related Assignee History].[Parent Incident Id].[Parent Incident Id].ALLMEMBERS 
    *[Related Assignee History].[Start Date Time].[Start Date Time].AllMembers 
    ) 
    } 
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS 

FROM(
    SELECT 
     (
     Filter(
      [Related Assignee History].[Modified By Id].Children 
      ,Left([Related Assignee History].[Modified By Id].CurrentMember.Name,1)="n" 
     ) 
     ) ON COLUMNS 
    FROM(
     SELECT 
      (
      { [Incident].[Owner Group].&[Directors Group]}) ON COLUMNS 
     FROM(
      SELECT 
       (
       {[Incident].[Reported Source].&[Self Service]}) ON COLUMNS 
      From(
       Select 
        (
         {[Related Assignee History].[Start Date Time].ITEM(0)}) on columns 
       FROM(
        SELECT({[Date Reported].[Year].&[2016] }) ON COLUMNS 
        FROM [Incident] 
        ) 
       ) 
      ) 
     ) 
    ); 

Ergebnisse sehen wie folgt aus:

David 123456 1/5/2016 10:03:29 AM 1 
David 111111 2/9/2016 10:05:31 AM 1 
Samuel 123456 2/9/2016 10:07:01 AM 1 
Samuel 111111 1/6/2016 12:03:29 AM 1 

Antwort

0

Schritt-für-Schritt

1.Initially ich durch die Vereinfachung durch das Löschen nicht wenige Klammern beginnen würde (hoffentlich!):

SELECT 
NON EMPTY 
    [Measures].[Count of Assignee Reassignments] ON 0, 
NON EMPTY 
    [Related Assignee History].[Modified By Id].[Modified By Id].ALLMEMBERS 
    *[Related Assignee History].[Parent Incident Id].[Parent Incident Id].ALLMEMBERS 
    *[Related Assignee History].[Start Date Time].[Start Date Time].ALLMEMBERS 
FROM(
    SELECT 
     FILTER(
      [Related Assignee History].[Modified By Id].Children 
      ,Left([Related Assignee History].[Modified By Id].CurrentMember.Name,1)="n" 
     ) ON 0 
    FROM(
     SELECT 
      [Incident].[Owner Group].&[Directors Group] ON 0 
     FROM(
      SELECT 
       [Incident].[Reported Source].&[Self Service] ON 0 
      FROM(
       SELECT 
        [Related Assignee History].[Start Date Time].ITEM(0) ON 0 
       FROM 
        (
        SELECT [Date Reported].[Year].&[2016] ON 0 
        FROM [Incident] 
        ) 
       ) 
      ) 
     ) 
    ); 

2.Wenn Sie nur an [Date Reported].[Year].&[2016] interessiert sind, dann lassen Sie uns aus den verrückten verschachtelten Subselects verschieben in eine WHERE Klausel - kann in ähnlicher Weise der Vorfälle Mitglieder in diese WHERE Klausel bewegen:

SELECT 
NON EMPTY 
    [Measures].[Count of Assignee Reassignments] ON 0, 
NON EMPTY 
    [Related Assignee History].[Modified By Id].[Modified By Id].ALLMEMBERS 
    *[Related Assignee History].[Parent Incident Id].[Parent Incident Id].ALLMEMBERS 
    *[Related Assignee History].[Start Date Time].[Start Date Time].ALLMEMBERS 
FROM 
    (
    SELECT 
     FILTER(
      [Related Assignee History].[Modified By Id].Children 
      ,Left([Related Assignee History].[Modified By Id].CurrentMember.Name,1)="n" 
     ) ON 0 
    FROM 
     (
     SELECT 
      [Related Assignee History].[Start Date Time].ITEM(0) ON 0 
     FROM [Incident] 
     ) 
    ) 
WHERE 
([Date Reported].[Year].&[2016] 
,[Incident].[Owner Group].&[Directors Group] 
,[Incident].[Reported Source].&[Self Service]); 

3.Now läßt die Filter in eine WITH Klausel bewegen und die Member_Caption Eigenschaft verwenden, um Namen zu finden, die mit N beginnen, wie Nathaniel - wir werden dann die in der SELECT Klausel benannte Menge verwenden:

WITH 
    SET [N_names] AS 
    FILTER(
      [Related Assignee History].[Modified By Id].[Modified By Id].MEMBERS 
      ,Left([Related Assignee History].[Modified By Id].CurrentMember.MEMBER_CAPTION,1) = 'N' 
    ) 
SELECT 
NON EMPTY 
    [Measures].[Count of Assignee Reassignments] ON 0, 
NON EMPTY 
    [N_names] 
    *[Related Assignee History].[Parent Incident Id].[Parent Incident Id].ALLMEMBERS 
    *[Related Assignee History].[Start Date Time].[Start Date Time].ALLMEMBERS 
FROM 
    (
    SELECT 
     [Related Assignee History].[Start Date Time].ITEM(0) ON 0 
    FROM [Incident] 
) 
WHERE 
([Date Reported].[Year].&[2016] 
,[Incident].[Owner Group].&[Directors Group] 
,[Incident].[Reported Source].&[Self Service]); 

4.I'm zu raten, dass dies [Related Assignee History].[Start Date Time].ITEM(0) Ihr Versuch, das min Datum für jede Person zu finden, so werde ich, dass für die Zeit Befinden löschen:

WITH 
    SET [N_names] AS 
    FILTER(
      [Related Assignee History].[Modified By Id].[Modified By Id].MEMBERS 
      ,Left([Related Assignee History].[Modified By Id].CurrentMember.MEMBER_CAPTION,1) = 'N' 
    ) 
SELECT 
NON EMPTY 
    [Measures].[Count of Assignee Reassignments] ON 0, 
NON EMPTY 
    [N_names] 
    *[Related Assignee History].[Parent Incident Id].[Parent Incident Id].ALLMEMBERS 
    *[Related Assignee History].[Start Date Time].[Start Date Time].ALLMEMBERS 
FROM [Incident] 
WHERE 
([Date Reported].[Year].&[2016] 
,[Incident].[Owner Group].&[Directors Group] 
,[Incident].[Reported Source].&[Self Service]); 

5.Now wird es etwas komplizierter:

WITH 
    SET [N_names] AS 
    FILTER(
      [Related Assignee History].[Modified By Id].[Modified By Id].MEMBERS 
      ,Left([Related Assignee History].[Modified By Id].CurrentMember.MEMBER_CAPTION,1) = 'N' 
    ) 
    SET [N_names_plusDates] AS 
    GENERATE(
     [N_names] AS N 
     , N.CURRENTMEMBER 
      * TAIL(
       NONEMPTY(
       [Related Assignee History].[Start Date Time].[Start Date Time].MEMBERS 
       ,N.CURRENTMEMBER 
       ) 
      ) 
    ) 
SELECT 
NON EMPTY 
    [Measures].[Count of Assignee Reassignments] ON 0, 
NON EMPTY 
    [N_names_plusDates] 
    *[Related Assignee History].[Parent Incident Id].[Parent Incident Id].ALLMEMBERS 
FROM [Incident] 
WHERE 
([Date Reported].[Year].&[2016] 
,[Incident].[Owner Group].&[Directors Group] 
,[Incident].[Reported Source].&[Self Service]);