SQL output using IIF()

imfarhan

Board Regular
Joined
Jan 29, 2010
Messages
125
Office Version
  1. 2016
Platform
  1. Windows
Hi SQL Gurus
The following query last column IIF( x=1, IIF( )) not showing the right reulst .
I would expect where the Source = "Initial Budget" and "WTE_Total" should show "Yes" and other rows sould show "NO"
but if you see the output in the screen below showing wrong and you can also see the IIF() condition in the SQL below as well
appreciate your help
Thanks
Farhan
WTE_Total_IIF(.JPG

SQL:
SELECT qry_bp_revised_adjustment_output_07.source,
       qry_bp_revised_adjustment_output_07.id,
       qry_bp_revised_adjustment_output_07.account_id,
       qry_bp_revised_adjustment_output_07.fin_yr,
       qry_bp_revised_adjustment_output_07.period,
       qry_bp_revised_adjustment_output_07.model_id,
       qry_bp_revised_adjustment_output_07.comment,
       qry_bp_revised_adjustment_output_07.elements,
       Sum(qry_bp_revised_adjustment_output_07.bud_val)            AS       SumOfBud_Val,
       qry_bp_revised_adjustment_output_07.bud_profile,
       qry_bp_revised_adjustment_output_07.wte_profile,
       Sum(qry_bp_revised_adjustment_output_07.sumofwte_val)       AS       SumOfSumOfWTE_Val,
       Sum(qry_bp_revised_adjustment_output_07.wte_val_adjustment) AS       SumOfWTE_Val_Adjustment,
IIF(
   qry_bp_revised_adjustment_output_07.source = "Initial Budget",     
          IIF(qry_bp_revised_adjustment_output_07.source = "WTE Total",     
           "Yes"  ,"NO"
)) AS Total_WTE
 
FROM   qry_bp_revised_adjustment_output_07
GROUP  BY qry_bp_revised_adjustment_output_07.source,
          qry_bp_revised_adjustment_output_07.id,
          qry_bp_revised_adjustment_output_07.account_id,
          qry_bp_revised_adjustment_output_07.fin_yr,
          qry_bp_revised_adjustment_output_07.period,
          qry_bp_revised_adjustment_output_07.model_id,
          qry_bp_revised_adjustment_output_07.comment,
          qry_bp_revised_adjustment_output_07.elements,
          qry_bp_revised_adjustment_output_07.bud_profile,
          qry_bp_revised_adjustment_output_07.wte_profile;
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
maybe i'm reading it wrong, but aren't you checking
if
qry_bp_revised_adjustment_output_07.source = "Initial Budget"
AND
qry_bp_revised_adjustment_output_07.source = "WTE Total"

it can't be both at the same time
 
Upvote 0
maybe i'm reading it wrong, but aren't you checking
if
qry_bp_revised_adjustment_output_07.source = "Initial Budget"
AND
qry_bp_revised_adjustment_output_07.source = "WTE Total"

it can't be both at the same time
Yes I think you are right.
How can I use OR within my IIF() condition
Thanks
 
Upvote 0
Yes I think you are right.
How can I use OR within my IIF() condition
Thanks
IIf(Eval([CountryRegion] In ("Canada","USA","Mexico")),"North America","Other")
I will try above n update here
 
Upvote 0
IIf(Eval([CountryRegion] In ("Canada","USA","Mexico")),"North America","Other")
I will try above n update here
Thanks James the following IIF() with OR is working

SQL:
    IIF(
         qry_bp_revised_adjustment_output_07.source = "Initial Budget"
      OR
        qry_bp_revised_adjustment_output_07.source = "WTE Total",
       "Yes","NO") AS Total_WTE
 
Upvote 0

Forum statistics

Threads
1,225,740
Messages
6,186,759
Members
453,370
Latest member
juliewar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top