<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use of CALENDAR() as a table variable in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1381083#M25240</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="52518" data-lia-user-login="Fowmy" class="lia-mention lia-mention-user"&gt;Fowmy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, that was one of the options I eventually presented to the OP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;Difference = DATEDIFF(Intervention[Start],Intervention[End],MINUTE)-1440*sumx(CALENDAR(Intervention[Start],Intervention[End]),if(WEEKDAY([Date],2)&amp;gt;5,1,0))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I first tried to use COUNTAX&amp;nbsp; but that doesn't seem to work well with binary values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;Difference = DATEDIFF(Intervention[Start],Intervention[End],MINUTE)-1440*COUNTAX(CALENDAR(Intervention[Start],Intervention[End]),WEEKDAY([Date],2)&amp;gt;5)&lt;/LI-CODE&gt;
&lt;P&gt;won't actually give the expected result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2020 20:48:56 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2020-09-18T20:48:56Z</dc:date>
    <item>
      <title>Use of CALENDAR() as a table variable</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380403#M25224</link>
      <description>&lt;P&gt;Here's the scenario:&amp;nbsp; Given a row in a table ("Intervention) with a set of two datetime columns ("Start" and "End")&amp;nbsp; I want to compute the difference between the two timestamps excluding certain days in between (let's say saturday and sunday).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First approach would be to create a table variable with a calendar of these two dates&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;EM&gt;Difference = &lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;var db = CALENDAR(Intervention[Start],Intervention[End])&lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;That seems to work as I get a proper row count from that when using test timestamps - it is including both the start and end days.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;According to the documentation the above should result in a single column table with a column "Date".&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&lt;A href="https://docs.microsoft.com/en-us/dax/calendar-function-dax" target="_blank" rel="noopener"&gt;https://docs.microsoft.com/en-us/dax/calendar-function-dax&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;However, any subsequent attempts to use that table (apart from a standalone COUNTROWS)&amp;nbsp; fails.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;&lt;EM&gt;return COUNTROWS(db)&lt;/EM&gt;&amp;nbsp; works but f&lt;/SPAN&gt;&lt;SPAN&gt;or example&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;var we = CALCULATE(COUNTROWS(db),WEEKDAY(db[Date],2)&amp;gt;5)&lt;/EM&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;fails to find the table 'db'. Any idea what might be going on here?&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;Update: ADDCOLUMNS() works. But why?&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;EM&gt;var we = ADDCOLUMNS(CALENDAR(Intervention[Start],Intervention[End]),"WE",if(WEEKDAY([Date],2)&amp;gt;5,1,0))&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 18 Sep 2020 15:30:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380403#M25224</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2020-09-18T15:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Use of CALENDAR() as a table variable</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380682#M25228</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;You can't use CALCULATE with virtual tables. It is the main reason I do not use CALCULATE very often:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/CALCUHATE-Why-I-Don-t-Use-DAX-s-CALCULATE-Function/ba-p/1248635" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Community-Blog/CALCUHATE-Why-I-Don-t-Use-DAX-s-CALCULATE-Function/ba-p/1248635&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will want to use SUMX, AVERAGEX, MAXX, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, for what you are originally doing, you could just use ([End] - [Start]) * 1. or DATEDIFF&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 16:24:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380682#M25228</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-09-18T16:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Use of CALENDAR() as a table variable</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380697#M25229</link>
      <description>&lt;P&gt;Thank you. As i mentioned in my update ADDCOLUMNS works too, even though the DAX intellisense complains passive-aggressively.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 16:28:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380697#M25229</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2020-09-18T16:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use of CALENDAR() as a table variable</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380718#M25230</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;Yeah, if you look at most of my DAX in things like the Quick Measures Gallery, I use tons of virtual tables. Everything in DAX pretty much works with virtual tables except CALCULATE and a few other functions that require physical tables like MAX, MIN, etc. so you have to use the equivalents MAXX, MINX, etc. But yeah, ADDCOLUMNS works great, I use ADDCOLUMNS with virtual tables a ton!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 16:39:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380718#M25230</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-09-18T16:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use of CALENDAR() as a table variable</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380775#M25232</link>
      <description>&lt;P&gt;I think the iffy part is that you need to know the column names that some of these virtual tables generate. Sometimes it seems to be [Value] but in the CALENDAR() example it is [Date]&amp;nbsp; etc.&amp;nbsp; Would be nice if DAX could address table columns by number.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 17:07:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380775#M25232</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2020-09-18T17:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: Use of CALENDAR() as a table variable</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380882#M25235</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;Yeah, it's always Value except for the Calendar. Intellisense/type ahead does work for these virtual tables. If I am not mistaken I believe: { (4, 5, 6), (7, 8, 9) } creaes Value1, Value2, Value3 columns but if just a single column gets created it is always Value unless it is from a Calendar function. If you create a table from a physical table,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VAR __Table = 'Table'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The names of the columns are the same as in the physical table. For most other ways of creating virtual tables or adding columns you explicitly name them.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 18:00:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1380882#M25235</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-09-18T18:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Use of CALENDAR() as a table variable</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1381077#M25239</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Agree with&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="313" data-lia-user-login="Greg_Deckler" class="lia-mention lia-mention-user"&gt;Greg_Deckler&lt;/a&gt;'s points and the explanations.&lt;BR /&gt;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;So in your case below approach should working, interested to know how you approached it.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Difference = 
var db = CALENDAR(Intervention[Start],Intervention[End])
return
SUMX(db,IF( WEEKDAY([Date],2) &amp;gt; 5, 1,0))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Notice the RED highlighting, it's still valid though.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;________________________&lt;/P&gt;&lt;P&gt;If my answer was helpful, please consider &lt;STRONG&gt;&lt;I&gt;Accept it as the solution&lt;/I&gt;&lt;/STRONG&gt;&lt;I&gt; to help the other members find it&lt;/I&gt;&lt;/P&gt;&lt;P&gt;Click on the &lt;STRONG&gt;Thumbs-Up icon &lt;/STRONG&gt;if you like this reply &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.youtube.com/channel/UCKwBEguA8IlBubIobaOormg?sub_confirmation=1" target="_blank" rel="noopener"&gt;&lt;FONT color="blue"&gt;YouTube&lt;/FONT&gt;&lt;/A&gt;&amp;nbsp; &lt;A href="https://linkedin.com/in/fowmy" target="_blank" rel="noopener"&gt;&lt;FONT color="blue"&gt;LinkedIn&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 20:37:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1381077#M25239</guid>
      <dc:creator>Fowmy</dc:creator>
      <dc:date>2020-09-18T20:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Use of CALENDAR() as a table variable</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1381083#M25240</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="52518" data-lia-user-login="Fowmy" class="lia-mention lia-mention-user"&gt;Fowmy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, that was one of the options I eventually presented to the OP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;Difference = DATEDIFF(Intervention[Start],Intervention[End],MINUTE)-1440*sumx(CALENDAR(Intervention[Start],Intervention[End]),if(WEEKDAY([Date],2)&amp;gt;5,1,0))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I first tried to use COUNTAX&amp;nbsp; but that doesn't seem to work well with binary values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;Difference = DATEDIFF(Intervention[Start],Intervention[End],MINUTE)-1440*COUNTAX(CALENDAR(Intervention[Start],Intervention[End]),WEEKDAY([Date],2)&amp;gt;5)&lt;/LI-CODE&gt;
&lt;P&gt;won't actually give the expected result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 20:48:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Use-of-CALENDAR-as-a-table-variable/m-p/1381083#M25240</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2020-09-18T20:48:56Z</dc:date>
    </item>
  </channel>
</rss>

