Forum Discussion
Complex IF Statement
- 5 years ago
Hi rebrow31 ,
Make use of variables to do that:
Shots =
Var Machine 1= IF(Downtime[Downtime] < 120, "0", IF(Downtime[Downtime] < 240, "1", IF(Downtime[Downtime] < 360, "2", IF(Downtime[Downtime] < 480, "3", IF(Downtime[Downtime] < 600, "4", IF(Downtime[Downtime] < 720, "5", IF(Downtime[Downtime] < 840, "6", IF(Downtime[Downtime] < 960, "7", IF(Downtime[Downtime] < 27000, "8"))))))))), IF(Downtime[Machine] = "DCM02", IF(Downtime[Downtime] < 300, "0", IF(Downtime[Downtime] < 600, "1", IF(Downtime[Downtime] < 900, "2", IF (Downtime[Downtime] < 1200, "3", IF (Downtime[Downtime] < 1500, "4", IF (Downtime[Downtime] < 1800, "5", IF (Downtime[Downtime] < 27000, "6"))))))))
Var Machine 2= conditions for machine 2
Var Machine 3= conditions for machine 2
Return IF (Downtime[Machine] = "DCM01", Var Machine 1, IF (Downtime[Machine] = "DCM02",Var Machine 1,
IF (Downtime[Machine] = "DCM03", Var Machine 3)))I hope this helps!
- Anonymous5 years ago
If all you want is a calculated column, then you should do it the way I'm going to describe. You should create a MachineConfig table with the following columns:
Machine|LowerBound|UpperBound|Value
------------------------------------
Machine1|0|3|0
Machine1|3|8|1
...
Machine2|0|2|0
Machine2|2|7|1
...
This is what it should look like in a good professional model.Once you've got this table, it's dead easy to add a column with the right Value's to your table T.
[Value] = /// calculated column in T var TheMachine = T[Machine] var TheMinutes = T[Minutes] var TheValue = MAXX( FILTER( // This filter should return just // one row if everything is correctly // coded. MachineConfig, MachineConfig[Machine] = TheMachine && // You should decide which bound // is inclusive and which is exclusive. Machine[LowerBound] <= TheMinutes && TheMinutes < Machine[UpperBound] ), MachineConfig[Value] ) return TheValueThe code will, of course, adjust itself automatically to the entries in the MachineConfig table.
Thank you so much for your help. It makes sense, I had no idea about variables. I am still getting an error messgae though, could you shed any light on what might be wrong?:
rebrow31 , The variable names could be a problem...should be a single string. My bad.
Machine_1, Machine_2.
Also, give a try for Anonymous 's solution.