{"id":512,"date":"2019-03-29T12:33:08","date_gmt":"2019-03-29T18:33:08","guid":{"rendered":"http:\/\/bekerman.com\/blog\/?p=512"},"modified":"2019-03-29T13:45:24","modified_gmt":"2019-03-29T19:45:24","slug":"formulas-1-0","status":"publish","type":"post","link":"https:\/\/bekerman.com\/blog\/formulas-1-0\/","title":{"rendered":"Formulas 1.0"},"content":{"rendered":"\n<p>The word <em>formula<\/em> comes from the Latin word <em>forma<\/em>, meaning shape or mold.  This is appropriate because formulas in Crystal Reports are about to mold, shape and change your world.  There are an unlimited number of ways formulas can be used.  I&#8217;ve seen some really cool and creative ways to use formulas and I&#8217;m still learning different ways to use them.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Let&#8217;s ease into learning about formulas with a simple need for our report.  We want to create a column that shows the gift amount but only for cash gifts.  Keep in mind that we still want to show all gifts on the report so the purpose here isn&#8217;t to apply any filters to the report.  When I say &#8220;cash gifts&#8221; I&#8217;m referring to gifts with a Gift Type = Cash.  <\/p>\n\n\n\n<p>On the right side of your Crystal Reports screen you should see a panel called Field Explorer.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Feild-Explorer.jpg\" alt=\"\" class=\"wp-image-518\" width=\"150\" height=\"118\"\/><\/figure><\/div>\n\n\n\n<p style=\"text-align:left\">  If the Field Explorer is not visible click on the View menu  on the top toolbar, then select Field Explorer.  There is also a Field Explorer button that looks like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Feild-Explorer-Button.jpg\" alt=\"\" class=\"wp-image-520\" width=\"47\" height=\"51\"\/><\/figure><\/div>\n\n\n\n<p>To create a new formula field right-click on the Formula Fields heading and select &#8220;New&#8230;&#8221;  This will open the Formula Name window.  Enter a name for the formula.  I am going to name our formula field &#8220;Cash Gift Amount.&#8221;  Be sure to use descriptive names that make sense so you (and the next employees in your position) will know what the formula field is.  After you click the OK button the Formula Workshop &#8211; Formula Editor window will appear.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1013\" height=\"600\" src=\"http:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Formula-Editor.jpg\" alt=\"\" class=\"wp-image-523\" srcset=\"https:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Formula-Editor.jpg 1013w, https:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Formula-Editor-300x178.jpg 300w, https:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Formula-Editor-768x455.jpg 768w, https:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Formula-Editor-500x296.jpg 500w\" sizes=\"(max-width: 1013px) 100vw, 1013px\" \/><\/figure>\n\n\n\n<p>There&#8217;s a lot going on here but don&#8217;t be afraid.  For now we only need to click in the blank area on the bottom center\/right of the window.  This is called the Formula Editing area and is where we, um, edit formulas.  Click anywhere in this area and a text cursor will appear, blinking and waiting for your command.<\/p>\n\n\n\n<p>The command will be a formula that says if the Gift Type is &#8220;Cash&#8221; then display the Gift Amount, otherwise display zero.  Let&#8217;s translate this into a formula in the Formula Editor.:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>If you just want to type in the formula without all the steps then skip to the last bullet point in the list.  <\/p><\/blockquote>\n\n\n\n<ul><li>Type <strong>If<\/strong><\/li><li>Above the Formula Editor are three windows, with the one on the left being the Report Fields area.  Click on the plus sign to the left of the data file path heading (in the image above this shows as H:\\SampleGiftExport&#8230;).  This will expand to show the tables in the data file.  Click the plus sign to the left of the Gf table, which will expand to show the fields in the table.  It should now look something like this:<\/li><li><\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Report-Fields-Area.jpg\" alt=\"\" class=\"wp-image-535\" width=\"149\" height=\"174\"\/><\/figure><\/div>\n\n\n\n<ul><li>Double-click on the Gf_Type field name.  This will insert the field name in the Formula Editor.  Make sure there is a space between the word If and the field name.<\/li><li>Type <strong>= <\/strong><\/li><li>Right-click on the Gf_Type field name in the Report Fields area and select Browse Data.  This will open a window with a list of all the data that is in the Gf_Type field.  <\/li><li>Double-click on <strong>Cash<\/strong>.  This will enter &#8220;Cash&#8221; in the Formula Editor window.  Your formula should now look like this: If {Gf.Gf_Type} = &#8220;Cash&#8221;<\/li><li>Type <strong>then<\/strong><\/li><li>Double-click on the Gf_Amount field name in the Report Fields area.  This will insert the field name in the Formula Editor.<\/li><li>Type <strong>else 0<\/strong><\/li><li>Your formula should now look like this: If {Gf.Gf_Type} = &#8220;Cash&#8221; then {Gf.Gf_Amount} else 0<\/li><\/ul>\n\n\n\n<p>Click the Save and Close button (upper-left corner of the Formula Workshop window).  Crystal Reports will check your formula for errors before closing and will display a warning message if there are any errors.<\/p>\n\n\n\n<p>The new formula field will now appear in the Field Explorer under the Formula Fields header:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"189\" height=\"182\" src=\"http:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Cash-Gift-Amount-Field.jpg\" alt=\"\" class=\"wp-image-549\"\/><\/figure><\/div>\n\n\n\n<p>The Cash Gift Amount can now be added to the report just like a regular data field.  Click and drag on the Cash Gift Amount field name and drop it to the right of the Gift Amount (Gf_Amount) field that is already on the report in the Details section.  Your report should now look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"498\" src=\"http:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Report-After-Cash-Gift-Amount.jpg\" alt=\"\" class=\"wp-image-550\" srcset=\"https:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Report-After-Cash-Gift-Amount.jpg 762w, https:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Report-After-Cash-Gift-Amount-300x196.jpg 300w, https:\/\/bekerman.com\/blog\/wp-content\/uploads\/2019\/03\/Report-After-Cash-Gift-Amount-459x300.jpg 459w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/figure>\n\n\n\n<p>Go ahead and try to add the second column we need for pledges following the same steps above.  We have some cleanup to do and I&#8217;ll cover that in the next article.  Also let me know (in the comments section below) if there are specific formulas you would like me to cover and I&#8217;d be glad to.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The word formula comes from the Latin word forma, meaning shape or mold. This is appropriate because formulas in Crystal Reports are about to mold, shape and change your world. There are an unlimited number of ways formulas can be &hellip; <a href=\"https:\/\/bekerman.com\/blog\/formulas-1-0\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":549,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/posts\/512"}],"collection":[{"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/comments?post=512"}],"version-history":[{"count":32,"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/posts\/512\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/posts\/512\/revisions\/552"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/media\/549"}],"wp:attachment":[{"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/media?parent=512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/categories?post=512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bekerman.com\/blog\/wp-json\/wp\/v2\/tags?post=512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}