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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.