{"id":744,"date":"2023-11-09T06:01:57","date_gmt":"2023-11-09T11:01:57","guid":{"rendered":"https:\/\/markwheeler.com\/?p=744"},"modified":"2023-11-09T06:01:57","modified_gmt":"2023-11-09T11:01:57","slug":"dax-add-business-days-to-date","status":"publish","type":"post","link":"https:\/\/www.markwheeler.com\/?p=744","title":{"rendered":"DAX: Add Business Days to Date"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">DAX calculated column code to add business days or network days to a date.<br><br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VAR __Date = IF(Table1[StartDate] &lt;> BLANK(), Table1[StartDate], date(2000, 1, 1))<br><br>\/\/ Days to Add; in my use case, the # of days was dependent on a category value. You can just set this a specific number if applicable<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VAR __Days = SWITCH(TRUE(),<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0 [Category] = &#8220;Complex&#8221;, 43,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0 [Category] = &#8220;Moderate&#8221;, 31,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0 [Category] = &#8220;Simple&#8221;, 29,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0 \u00a0 )<br><br>\/\/ This var creates a temp calendar padded out by the *3 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VAR __Calendar = ADDCOLUMNS(CALENDAR(__Date, __Date + (__Days) * 3), &#8220;Weekday&#8221; , WEEKDAY([Date],2))<br><br>\/\/ filter out the weekends<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">VAR __CalendarX = FILTER(__Calendar, [Weekday] &lt; 6)<br><br>\/\/ add an addition column to the temp calendar that counts the # of days needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0VAR __CalendarY = ADDCOLUMNS(__CalendarX,\u00a0 &#8220;Days&#8221;, COUNTROWS(FILTER(__CalendarX, [Date] &lt;= EARLIER([Date]))<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp; &nbsp; )<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">RETURN<br><br>\/\/ returns the new &#8216;due&#8217; date that is __Days out from the StartDate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u00a0 \u00a0SELECTCOLUMNS(FILTER(__CalendarY, [Days] = __Days), &#8220;Date&#8221;, [Date])<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>DAX calculated column code to add business days or network days to a date. VAR __Date = IF(Table1[StartDate] &lt;> BLANK(), Table1[StartDate], date(2000, 1, 1)) \/\/ Days to Add; in my use case, the # of days was dependent on a category value. You can just set this a specific number [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[7],"tags":[],"class_list":["post-744","post","type-post","status-publish","format-standard","hentry","category-power-bi"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=744"}],"version-history":[{"count":0,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/744\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}