<?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: Dax Cacluate expression with Excel pivot table Grand totals in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2824460#M89757</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="452629" data-lia-user-login="gustafwallin" class="lia-mention lia-mention-user"&gt;gustafwallin&lt;/a&gt; , Refer if these two can help&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-divide-distribute-values-between-start-date-or-end-date/ba-p/1503785" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/How-to-divide-distribute-values-between-start-date-or-end-date/ba-p/1503785&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2022 03:54:43 GMT</pubDate>
    <dc:creator>amitchandak</dc:creator>
    <dc:date>2022-10-07T03:54:43Z</dc:date>
    <item>
      <title>Dax Cacluate expression with Excel pivot table Grand totals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2823243#M89668</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two distinct questions relation to solving the following matters. One is pure DAX related, and the other is why the grand totals in my pivot table does not compute accurately. I do hower think they are related in some way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basic question: I wish to calculate the total number of "active machines" in a certain year to perform a cost analysis. This means&amp;nbsp; each machine is active between the time of Purchasing and Decomission.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following INVENTORY table shows this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Machine nr&lt;/TD&gt;&lt;TD&gt;PurchaseDate&lt;/TD&gt;&lt;TD&gt;Decomissioned&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2017-01-02&lt;/TD&gt;&lt;TD&gt;2018-05-10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2018-01-02&lt;/TD&gt;&lt;TD&gt;2021-09-13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2010-06-05&lt;/TD&gt;&lt;TD&gt;2016-09-13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2018-01-02&lt;/TD&gt;&lt;TD&gt;2021-09-13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2018-01-02&lt;/TD&gt;&lt;TD&gt;2021-09-13&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Dax formula im trying to write should include the active machine to the year it was decomissioned.&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example: the number of machines active during 2018 would be 4 (Machine number 1, 2, 4, 5) even though machinie 1 was decommisioned during 2018.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My Dax formula looks like this (using a date table) but it does not seem to work correctly:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(for context&amp;nbsp; the AO__Tabell is registering costs relating to the machines each year which we sum for each corresponding year. )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;=VAR maxDate=ENDOFYEAR(AO___Tabell[Reg. date]) -- Filtered by context in the pivot table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;RETURN CALCULATE(COUNTROWS(INVENTORY);FILTER(INVENTORY;INVENTORY[PurchaseDate] &amp;lt;=maxDate &amp;amp;&amp;amp; (INVENTORY[Decomissioned] &amp;gt;maxDate || INVENTORY[Decommisioned] IN DATESINPERIOD('Date'[Date];STARTOFYEAR('Date'[Date]);1;YEAR))))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition, while this DAX does not work perfectly - I get very wrong Grand totals in my pivot table (see picture below). Im guessing this has to do with the grand totals in pivot tables not taking into account the DAX filters im using. If that is the case, how can the DAX formula be changed to accomodate this?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Very thankful for any help that is available!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gustaf&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 15:05:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2823243#M89668</guid>
      <dc:creator>gustafwallin</dc:creator>
      <dc:date>2022-10-06T15:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Cacluate expression with Excel pivot table Grand totals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2824460#M89757</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="452629" data-lia-user-login="gustafwallin" class="lia-mention lia-mention-user"&gt;gustafwallin&lt;/a&gt; , Refer if these two can help&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/How-to-divide-distribute-values-between-start-date-or-end-date/ba-p/1503785" target="_blank"&gt;https://community.powerbi.com/t5/Community-Blog/How-to-divide-distribute-values-between-start-date-or-end-date/ba-p/1503785&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 03:54:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2824460#M89757</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2022-10-07T03:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Cacluate expression with Excel pivot table Grand totals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2825338#M89813</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="452629" data-lia-user-login="gustafwallin" class="lia-mention lia-mention-user"&gt;gustafwallin&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;According to your description, I made a sample, and here is my solution.&lt;/P&gt;
&lt;P&gt;Create a DATE table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;DATE =
CALENDAR ( MIN ( 'Table'[PurchaseDate] ), MAX ( 'Table'[Decomissioned] ) )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do not establish a relationship between two tables.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Create a measure to display the active machine nr.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;active machines =
VAR _slice =
    ENDOFYEAR ( 'DATE'[Date] )
RETURN
    IF (
        COUNTROWS (
            FILTER (
                _slice,
                MAX ( 'Table'[PurchaseDate] ) &amp;lt;= _slice
                    &amp;amp;&amp;amp; MAX ( 'Table'[Decomissioned] ) &amp;gt; _slice
                    || MAX ( 'Table'[Decomissioned] )
                        IN DATESINPERIOD ( 'DATE'[Date], STARTOFYEAR ( 'DATE'[Date] ), 1, YEAR )
            )
        ) &amp;gt; 0,
        MAX ( 'Table'[Machine nr] ),
        BLANK ()
    )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a measure to calculate the total numbers of the active machines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;number of active machines =
VAR _slice =
    ENDOFYEAR ( 'DATE'[Date] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[PurchaseDate] &amp;lt;= _slice
                &amp;amp;&amp;amp; (
                    'Table'[Decomissioned] &amp;gt; _slice
                        || 'Table'[Decomissioned]
                            IN DATESINPERIOD ( 'DATE'[Date], STARTOFYEAR ( 'DATE'[Date] ), 1, YEAR )
                )
        )
    )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Put “Year” of DATE into slicer, and then select the year, you will get the Final output:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I attach my sample below for your reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Community Support Team _ xiaosun&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;helps,&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 09:43:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2825338#M89813</guid>
      <dc:creator>v-xiaosun-msft</dc:creator>
      <dc:date>2022-10-07T09:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Cacluate expression with Excel pivot table Grand totals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2825959#M89850</link>
      <description>&lt;P&gt;Thank you very much for this elaborate reply. This was way more than I hoped for. This definately does the trick, even though I'll have to sharpen my DAX skills to fully understand the formulas. I'll try and make the connections in Power BI to my larger Data model!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thanks a lot!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 13:47:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2825959#M89850</guid>
      <dc:creator>gustafwallin</dc:creator>
      <dc:date>2022-10-07T13:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Cacluate expression with Excel pivot table Grand totals</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2825975#M89851</link>
      <description>&lt;P&gt;Hi Amit!&lt;/P&gt;&lt;P&gt;Thanks for the links, that is some clean looking variants that seem to somewhat apply to my specific problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll have to look into it more closely, but the first example you sent seemed very similar.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 13:52:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Cacluate-expression-with-Excel-pivot-table-Grand-totals/m-p/2825975#M89851</guid>
      <dc:creator>gustafwallin</dc:creator>
      <dc:date>2022-10-07T13:52:10Z</dc:date>
    </item>
  </channel>
</rss>

