{"id":2757,"date":"2016-09-09T09:39:40","date_gmt":"2016-09-09T13:39:40","guid":{"rendered":"http:\/\/kenhamady.com\/cru\/?p=2757"},"modified":"2016-09-09T09:39:40","modified_gmt":"2016-09-09T13:39:40","slug":"mixing-and-and-or-or-and-and-if-then-else","status":"publish","type":"post","link":"https:\/\/kenhamady.com\/cru\/archives\/2757","title":{"rendered":"Mixing (AND and OR) or  (AND and IF THEN ELSE)"},"content":{"rendered":"<p>One common problem, especially in selection formulas, is when you have both AND and OR but no parentheses to clarify which should come first.\u00a0\u00a0 Take the following example:<\/p>\n<p style=\"padding-left: 30px;\"><code>{Orders.Order Amount} &gt; 5000 and<br \/>\n{Customer.Country} &lt;&gt; \"USA\" or<br \/>\n{Customer.Region} = \"CA\"<\/code><\/p>\n<p>If there is a CA order for $2,500, will it meet the criteria?\u00a0 Using the above formula, yes.\u00a0 That is because without any parentheses, the AND takes priority over the OR.\u00a0 So in English this formula means:<\/p>\n<p>Return all records that are outside the US and above $5,000. Also return all records that are in CA regardless of the amount.<\/p>\n<p>If I intended that ALL locations were above $5,000\u00a0 then I need to put parentheses around the OR to tell the report to treat that as one rule.\u00a0 It could look like this:<\/p>\n<p style=\"padding-left: 30px;\"><code>{Orders.Order Amount} &gt; 5000 and<br \/>\n( {Customer.Country} &lt;&gt; \"USA\" or<br \/>\n{Customer.Region} = \"CA\" ) <\/code><\/p>\n<p>A similar thing happens when you include an IF THEN ELSE in your selection formula like this:<\/p>\n<p style=\"padding-left: 30px;\"><code>if {?StateParameter} = \"ALL\"<br \/>\nthen True<br \/>\nelse {?StateParameter} = {Table.State}<br \/>\nand {Table.Date} in {?DateRange}<\/code><\/p>\n<p>In this case the AND will combine the DateRange rule with the ELSE.\u00a0 The DateRange parameter will be ignored when you select ALL States.\u00a0 To apply the DateRange in ALL cases you need to put the IF THEN ELSE statement inside a pair of parentheses like this:<\/p>\n<p style=\"padding-left: 30px;\"><code>( if {?StateParameter} = \"ALL\"<br \/>\nthen True<br \/>\nelse {?StateParameter} = {Table.State} )<br \/>\nand {Table.Date} in {?DateRange}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One common problem, especially in selection formulas, is when you have both AND and OR but no parentheses to clarify which should come first.\u00a0\u00a0 Take the following example: {Orders.Order Amount} &gt; 5000 and {Customer.Country} &lt;&gt; &#8220;USA&#8221; or {Customer.Region} = &#8220;CA&#8221; If there is a CA order for $2,500, will it meet the criteria?\u00a0 Using the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,2],"tags":[],"class_list":["post-2757","post","type-post","status-publish","format-standard","hentry","category-bugs","category-formulas"],"_links":{"self":[{"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/posts\/2757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/comments?post=2757"}],"version-history":[{"count":0,"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/posts\/2757\/revisions"}],"wp:attachment":[{"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/media?parent=2757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/categories?post=2757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenhamady.com\/cru\/wp-json\/wp\/v2\/tags?post=2757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}