Forum

Power Query Multipl...
 
Notifications
Clear all

Power Query Multiple IF criteria formula

4 Posts
2 Users
0 Reactions
90 Views
(@juliam)
Posts: 4
Active Member
Topic starter
 

I'm trying to recreate an Excel formula in Power Query, but am unsuccessful.  The formula today looks at a numeric value and categorizes it, for example, if the value is greater than 10,000, then category >$10,000 is the result in the cell.  I am using Add column, Custom Column, see example formula that is giving Expression.Error: We cannot apply operator < to types Number and Text.

Details:

  Operator=< 

  Left=10000

  Right=-

if [YTD Revenue USD] <10000 then "<$10k"
else if [YTD Revenue USD] >500000 then ">$500k"
else if [YTD Revenue USD] >1000000 then ">$1M"
else ""

 
Posted : 08/02/2022 3:19 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Julia,

Check if the values in your [YTD Revenue USD] column are actually numbers.  PQ is complaining that it's seeing text in that column.

Regards

Phil

 
Posted : 08/02/2022 8:26 pm
(@juliam)
Posts: 4
Active Member
Topic starter
 

Thank you Phil!  I figured that was the issue, as my column comes in as type ABC, but it is a number field (revenue).  When I try other data types, the zero value items return ERROR.  No other data type works.  I think this is because the data has a - in it for items with no revenue.  I replaced the - with a 0 then I was able to change the data type without error and then add my formula.  Whew!

Thanks for the quick reply!

 
Posted : 09/02/2022 2:33 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

No worries Julia.  Yes as you discovered a - in a numeric field needs to be changed to something else, like 0

 
Posted : 09/02/2022 7:30 pm
Share: