Forum Discussion
Need help to write Multiple IF statements in a Calculated Column
- Anonymous3 years ago
Hi Anonymous , ryan_mayu ,
I was able to get the below logic(no syntax issues) in powerBI for the above logic but how can I include THEN, END, ELSE in my logic below (as these logics are very important to be included to get the exact output).
Please help
Ageing Category =IF ([Category] <> "Future Offboard",IF ([Category] <> "Unallocated",SWITCH (TRUE (),CustomSQL_BenchReport[Delivery_Aging] <= 30, "0-30 Days",CustomSQL_BenchReport[Delivery_Aging]>30 && CustomSQL_BenchReport[Delivery_Aging] <= 60, "31-60 Days",CustomSQL_BenchReport[Delivery_Aging] >60 && CustomSQL_BenchReport[Delivery_Aging] <= 90, "61-90 Days",CustomSQL_BenchReport[Delivery_Aging] >90 && CustomSQL_BenchReport[Delivery_Aging] <= 180, "91-180 Days",CustomSQL_BenchReport[Delivery_Aging] > 180, ">180 Days"),SWITCH (TRUE (),CustomSQL_BenchReport[unallocated_aging] <= 30, "0-30 Days",CustomSQL_BenchReport[unallocated_aging] >30 && CustomSQL_BenchReport[unallocated_aging] <= 60, "31-60 Days",CustomSQL_BenchReport[unallocated_aging] >60 && CustomSQL_BenchReport[unallocated_aging] <= 90, "61-90 Days",CustomSQL_BenchReport[unallocated_aging] >90 && CustomSQL_BenchReport[unallocated_aging] <= 180, "91-180 Days",CustomSQL_BenchReport[unallocated_aging] > 180, ">180 Days")),SWITCH (TRUE (),CustomSQL_BenchReport[No_of_days] <= 30, "0-30 Days",CustomSQL_BenchReport[No_of_days] >30 && CustomSQL_BenchReport[No_of_days] <= 60, "31-60 Days",CustomSQL_BenchReport[No_of_days] >60 && CustomSQL_BenchReport[No_of_days] <= 90, "61-90 Days",CustomSQL_BenchReport[No_of_days] >90 && CustomSQL_BenchReport[No_of_days] <= 180, "91-180 Days",CustomSQL_BenchReport[No_of_days] >180, ">180 Days"))
Hi Anonymous ,
You can try this code to create a calculated column.
Ageing Category =
IF (
[Category] <> ' Future Offboard',
IF (
[Category] <> 'Unallocated',
SWITCH (
TRUE (),
[Delivery Aging] <= 30, '0-30 Days',
[Delivery Aging] <= 60, '31-60 Days',
[Delivery Aging] <= 90, '61-90 Days',
[Delivery Aging] <= 180, '91-180 Days',
'>180 Days'
),
SWITCH (
TRUE (),
[unallocated_aging] <= 30, '0-30 Days',
[unallocated_aging] <= 60, '31-60 Days',
[unallocated_aging] <= 90, '61-90 Days',
[unallocated_aging] <= 180, '91-180 Days',
'>180 Days'
)
),
SWITCH (
TRUE (),
[No_of_days] <= 30, '0-30 Days',
[No_of_days] <= 60, '31-60 Days',
[No_of_days] <= 90, '61-90 Days',
[No_of_days] <= 180, '91-180 Days',
'>180 Days'
)
)
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
Thanks for replying to my query.
I tried to replicate your logic in the Power BI column, But I get the below error:
"Cannot find table "furture Offboard" . Where as 'Future Offboard" is one of the value in the CATEGORY column . Please help.
- Anonymous3 years agoNot applicable
Anonymous : Hi, Just checking if you can please give me your thoughts on the above error after implementing your logic. Thanks
- ryan_mayu3 years ago
Super User
pls try double quotation marks instead.
"Future Offboard"
- Anonymous3 years agoNot applicable
ryan_mayu , I tried it worked but now i got the below error:
Delivery Ageing is a column and "0-30 days" is a bucket
- ryan_mayu3 years ago
Super User
same change to double quotation marks
"0-30days"
- Anonymous3 years agoNot applicable
Thanks !