Search code examples
sqlamazon-web-servicesamazon-athenacalculated-fieldamazon-quicksight

How to write calculated field formula in AWS QuickSight using ifelse


I am trying to write a formula that would calculate a discounted cost depending on the date.

Any costs that accrue after May 2019 would have a discount rate of 7% and anything prior to that would be 6%.

This is what I have for the formula but it's saying the syntax is incorrect. Any help would be much appreciated.

ifelse(month >= 5 AND year >= 2019), then {unblended_cost} - ({unblended_cost} * 0.07), else {unblended_cost} - ({unblended_cost} * 0.06))

Solution

  • Try the following and let me know if you encounter other errors

    ifelse(                                                                         
      month >= 5 AND year >= 2019,                                                  
      {unblended_cost} - ({unblended_cost} * 0.07),                                 
      {unblended_cost} - ({unblended_cost} * 0.06)                                  
    ) 
    

    Essentially ifelse can be thought of as a single function, and the then and else keywords are extraneous.