Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ArtieLadie
Regular Visitor

with CTE statement giving error

I am pulling query from Oracle Database into Power BI that outputs this

 

 

but I want it to output this

 

 

 

I thought MIN(I.CREATIONDATE) would give date-time with earliest hour in my original query

 

 

SELECT TO_CHAR(MIN(I.INCIDENTID))               AS "Incident ID",
          MIN(I.CREATIONDATE)            AS "Creation Date",
          TO_CHAR(I.CREATIONDATE,'MM-DD-YYYY')            AS "Date",
          TRIM(MO.DOMAINUSERNAME)               AS "Login ID",  
          TRIM(M.MESSAGESUBJECT)                AS "Email Subject"
FROM   MESSAGE M 
JOIN   INCIDENT I 
ON     M.MESSAGESOURCE = I.MESSAGESOURCE 
AND       M.MESSAGEID = I.MESSAGEID
AND    M.MESSAGEDATE    = I.MESSAGEDATE 
JOIN   MESSAGEORIGINATOR MO
ON     M.MESSAGEORIGINATORID = MO.MESSAGEORIGINATORID                  
GROUP BY TO_CHAR(I.CREATIONDATE,'MM-DD-YYYY'),
         TRIM(MO.DOMAINUSERNAME),
         TRIM(M.MESSAGESUBJECT)

 

Then I was advised to use CTE with row_number() but now I get 

 

Message=ORA-00933: SQL command not properly ended

 

 

I tried many variations. How to fix this?

 

with CTE as (
SELECT MyTable.*, 
       row_number() over (PARTITION BY MIN(I.CREATIONDATE) ORDER BY I.CREATIONDATE) AS rn   
FROM MyTable
)
SELECT *
FROM CTE
WHERE rn = 1

SELECT TO_CHAR(MIN(I.INCIDENTID))               AS "Incident ID",
          MIN(I.CREATIONDATE)            AS "Creation Date",
          TO_CHAR(I.CREATIONDATE,'MM-DD-YYYY')            AS "Date",
          TRIM(MO.DOMAINUSERNAME)               AS "Login ID",  
          TRIM(M.MESSAGESUBJECT)                AS "Email Subject"
FROM   MESSAGE M 
JOIN   INCIDENT I 
ON     M.MESSAGESOURCE = I.MESSAGESOURCE 
AND       M.MESSAGEID = I.MESSAGEID
AND    M.MESSAGEDATE    = I.MESSAGEDATE 
JOIN   MESSAGEORIGINATOR MO
ON     M.MESSAGEORIGINATORID = MO.MESSAGEORIGINATORID                  
GROUP BY TO_CHAR(I.CREATIONDATE,'MM-DD-YYYY'),
         TRIM(MO.DOMAINUSERNAME),
         TRIM(M.MESSAGESUBJECT)
0 REPLIES 0

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.