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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ArtieLadie
Regular Visitor

Oracle SQL CTE not working - any workarounds???

I've been working on a query for nearly a month

 

I import Oracle SQL into PowerBI, and I wish for distinct columns

 

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  INCIDENT I 
   JOIN  MESSAGE M
   ON M.MESSAGEID = I.MESSAGEID
   JOIN   MESSAGEORIGINATOR MO
   ON     M.MESSAGEORIGINATORID = MO.MESSAGEORIGINATORID           
   GROUP BY TO_CHAR(I.CREATIONDATE,'MM-DD-YYYY'),
            TRIM(MO.DOMAINUSERNAME),
            TRIM(M.MESSAGESUBJECT)

 

This query gives bad result

 

 

bad.png

 

 

But I am looking for good result, i.e.

 

good.png

 

 

I have been advised to use INNER JOIN and HAVING COUNT(*)=1, which partially fixes the problem, i.e. instead of 3 or 4 duplicates, I get 2 duplicates.

 

Now I have been advised to use CTE ---- unfortunately this gives error in PowerBI. How to fix this?

 

with cte as (SELECT TO_CHAR(I.INCIDENTID))                  AS "Incident ID",
              (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",
              row_number() over(partition by TO_CHAR(I.CREATIONDATE,'MM-DD-YYYY'),
            TRIM(MO.DOMAINUSERNAME), TRIM(M.MESSAGESUBJECT) order by TO_CHAR(I.INCIDENTID)),I.CREATIONDATE) rn 
       FROM  INCIDENT I 
       JOIN  MESSAGE M
       ON M.MESSAGEID = I.MESSAGEID
       JOIN   MESSAGEORIGINATOR MO
       ON     M.MESSAGEORIGINATORID = MO.MESSAGEORIGINATORID 
) select * from cte where rn=1

PowerBI Error

error.PNG

 

 

 

3 REPLIES 3
ArtieLadie
Regular Visitor

Thank you for your response --- however I still need assistance

 

I already made sure

1. Syntax is correct.

2. FROM is in correct place, and no spelling errors have occurred.

3. No reserved words were used as an alias

Hi @ArtieLadie ,

 

Maybe you need to check it again , for example the bracket ")" in a wrong place, or you may ask someone great who is good at it.

 

1.png

 

 

 

 

 

 

 

 

Best Regards,

Amy

v-xicai
Community Support
Community Support

Hi @ArtieLadie ,

 

To work around the ORA-00923 error, you can check the following points:

 

1.Correct the syntax. Make sure you have placed the keyword FROM in its correct place, and that no spelling errors have occurred

2.If you used quotation marks in an alias, make sure that they have properly enclosed the alias and that they are double quotation marks.

3.Make sure no reserved words were used as an alias. See the Oracle appendix for reserved words to view a complete list. 

 

You can learn more: http://www.dba-oracle.com/t_ora_00923_from_keyword_not_found_where_expected.htm

                                     https://www.tekstream.com/oracle-error-messages/ora-00923-from-keyword-not-found-where-expected/

Please understand that this link is provided “AS IS” with no warranties or guarantees of content changes, and confers no rights.

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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