Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Clay
Contributor
Contributor

Use SQL "Sum if" in load to split "Amount" to two columns

I'm using SQL in my load statement to bring in data from an Oracle DB using OLEDB

The fact table has a column "AMOUNT" which contains both dollars and headcount. I can separate these from each other based on another field, let's call it "ACCOUNT", where "ACCOUNT" can either be equal to "EXPENSE" or "HEADCOUNT".

 

I can't find the correct syntax in the load to say:

If ACCOUNT = EXPENSE, sum AMOUNT as "EXPENSE",

If ACCOUNT = HEADCOUNT, sum AMOUNT as "HEADCOUNT"  

 

Example of current load statement, which works fine, but is not yet splitting the AMOUNT field:


SQL SELECT


ACCOUNT,
Sum (AMOUNT) as Amount

FROM
EDW."FactTable"

WHERE

AMOUNT <> 0

GROUP BY

ACCOUNT

;

 

Any help getting the right syntax for the sumif would be greatly appreciated, thanks!

2 Replies
Taoufiq_Zarra

Maye be :

Load 
ACCOUNT,
if(ACCOUNT='EXPENSE',Amount) as EXPENSE,
if(ACCOUNT='HEADCOUNT',Amount) as HEADCOUNT
;

SQL SELECT

ACCOUNT,
Sum (AMOUNT) as Amount

FROM
EDW."FactTable"

WHERE

AMOUNT <> 0

GROUP BY

ACCOUNT

;
Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Brett_Bleess
Former Employee
Former Employee

If Taoufiq's reply got you what you needed, we would appreciate it if you would return to the thread and close it out by using the Accept as Solution button on his post to give him credit for the help and let other Members know that worked.  

The other option would be to use our Load statement and our script functions to do the work you were trying to do via Oracle SQL statements, as sometimes the Oracle drivers will not process some statements, but the best place to confirm that is going to be on Oracle Community/Support site, as they are the experts on the driver.  Sorry I do not have anything better to offer.

https://help.qlik.com/en-US/qlikview/April2020/Subsystems/Client/Content/QV_QlikView/Scripting/Scrip...

And I completely missed the fact Taoufiq did exactly what I was suggesting, my bad! 🙂

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.