Forum Discussion
If statement to build Time Range
Hello
I have custom column that has this code.
It works fine for me. It returns 1-2 minutes. I'd need to see your data to understand what is going on.
Rather than nested IF statements, consider switching to the SWITCH function. For example:
New Talk Time = SWITCH( TRUE(), Maintel_Data[Talk_Time_Seconds] >= 0 && Maintel_Data[Talk_Time_Seconds] <= 30, "Under 30 Seconds", Maintel_Data[Talk_Time_Seconds] > 30 && Maintel_Data[Talk_Time_Seconds] <= 60, "30-60 Seconds", Maintel_Data[Talk_Time_Seconds] > 60 && Maintel_Data[Talk_Time_Seconds] <= 120, "1-2 Minutes", Maintel_Data[Talk_Time_Seconds] > 120 && Maintel_Data[Talk_Time_Seconds] <= 180, "2-3 Minutes", Maintel_Data[Talk_Time_Seconds] > 180 && Maintel_Data[Talk_Time_Seconds] <= 240, "3-4 Minutes" )
5 Replies
- edhansCommunity Champion
It works fine for me. It returns 1-2 minutes. I'd need to see your data to understand what is going on.
Rather than nested IF statements, consider switching to the SWITCH function. For example:
New Talk Time = SWITCH( TRUE(), Maintel_Data[Talk_Time_Seconds] >= 0 && Maintel_Data[Talk_Time_Seconds] <= 30, "Under 30 Seconds", Maintel_Data[Talk_Time_Seconds] > 30 && Maintel_Data[Talk_Time_Seconds] <= 60, "30-60 Seconds", Maintel_Data[Talk_Time_Seconds] > 60 && Maintel_Data[Talk_Time_Seconds] <= 120, "1-2 Minutes", Maintel_Data[Talk_Time_Seconds] > 120 && Maintel_Data[Talk_Time_Seconds] <= 180, "2-3 Minutes", Maintel_Data[Talk_Time_Seconds] > 180 && Maintel_Data[Talk_Time_Seconds] <= 240, "3-4 Minutes" )- AnonymousNot applicable
I agree with edhans,
Your code works fine for me, but a switch to Switch would be much cleaner and easier to read. Below are 2 columns, one with your code and one with edhans.
- GrahamR99Resolver I
Hello
I didn't think it was the data but after checking it was.
I was converting seconds but didn't relise it was only getting the seconds, I needed to add the hours and the minutes to my seconds field.
I used your switch code and it also worked.
Regards
GrahamR99
- edhansCommunity Champion
Excellent. Glad you got it sorted out, and learned a new function! 😁 SWITCH is so much easier to read and edit.