Working on something in QS and have hit a snag - in a nutshell;
I’m making a dashboard that tracks consumables usage. I want to create the following logic but cannot work out how to do it using ifelse;
If TotalCoffee < 1 then I want a fixed value of “Spread Across Both Machines” but if TotalCoffee > 1 then I want the value to be whatever my calculated field DecafMachine1 equals
In this instance, TotalCoffee is a calculated field equal to DecafMachine1 + DecafMachine2
The formula I’ve written is giving me a syntax error but I genuinely cannot work out why;
ifelse(TotalCoffee < 1, ‘Spread Across Both Machines’, ({DecafMachine1}))
Hello @Steezy97 - This could be due to datatype mismatch between string and number. It seems your fixed value is text (then portion) and decafmachine1 is numeric(else portion). You need to cast the decafmachine1 into string and that should hopefully resolve your issue. Hope this helps!!
Yeah no problem, how do I share it as I cannot upload it to this comment?
Just for full clarity, DecafMachine1 and DecafMachine2 are both calculated fields made up of countifs on my dataset not fields in the dataset. Does this make a difference?
All of the other calculated fields like CountDecafSSChocolate are - countIf({Beverage Family}, {Beverage Family} = “Chocolate” AND MachineMilkType = “Semi-Skimmed” AND {Blend Type}=“Decaf”)
DaysInMonth - distinct_count({Local Date}) as the sheet has a filter to only show the last months’ data
Hi @Steezy97 , this error is interesting. Simple thing, but can you try deleting those fields in your formula and inserting them again? I wonder if any of them were deleted and then re-added with the same names, QuickSight might be holding on to the ID’s of the old versions. Your syntax looks OK to me, so I would try to just recreate this calc first.
Since we haven’t heard back from you, assume Jesse’s suggestion resolved your issue. I’m marking Jesse’s reply as solution here. Please do let us know in case you are still facing issues with this.