<?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: Sum for last days of month per each category - how to simplify in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-for-last-days-of-month-per-each-category-how-to-simplify/m-p/2578934#M73936</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please try the below measure.&lt;/P&gt;
&lt;P&gt;I also attached the pbix file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Rolling3Months =
VAR _EndDate =
    MAX ( v_dimdate[Date] )
VAR _months =
    SUMMARIZE (
        FILTER (
            ALL ( v_dimdate ),
            v_dimdate[Date] IN DATESINPERIOD ( v_dimdate[Date], _EndDate, -3, MONTH )
        ),
        v_dimdate[YearMonth]
    )
VAR _Inventory =
    SUMX ( _months, [Inventory Cost] )
RETURN
    IF ( [Inventory Cost] &amp;lt;&amp;gt; BLANK (), _Inventory )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jun 2022 02:33:06 GMT</pubDate>
    <dc:creator>Jihwan_Kim</dc:creator>
    <dc:date>2022-06-15T02:33:06Z</dc:date>
    <item>
      <title>Sum for last days of month per each category - how to simplify</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-for-last-days-of-month-per-each-category-how-to-simplify/m-p/2578504#M73913</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a quite peculiar problem. I have a column with values that represents the state of Inventory for each Site (category).&amp;nbsp;&lt;BR /&gt;Which means that the most recent one value for each month is always last day per each site per month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;for site &lt;STRONG&gt;667&lt;/STRONG&gt; for november its going to be value&amp;nbsp;&lt;STRONG&gt;5 252 235.74&lt;/STRONG&gt; (31/12/2021) but for site &lt;STRONG&gt;200&lt;/STRONG&gt; its going to be&amp;nbsp;&lt;STRONG&gt;79 967 894.18&lt;/STRONG&gt; (30/12/2021)&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sum of those values should be&amp;nbsp;&lt;STRONG&gt;85 220 129.92&amp;nbsp;&lt;/STRONG&gt;which is state of inventory for those two sites per december.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to calculate this with this measure:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Inventory Cost = 
VAR _pretable =
    ADDCOLUMNS (
        SUMMARIZE (
            v_factinventorytransactions,
            v_dimdate[DateId],
            v_factinventorytransactions[SiteId]
        ),
        "InventoryCost", CALCULATE ( AVERAGE ( v_factinventorytransactions[RunningCost] ) )
    )
VAR _table =
    FILTER (
        _pretable,
        VAR _MaxDate =
            CALCULATE (
                MAX ( v_factinventorytransactions[InventoryTransactionDateId] ),
                ALLSELECTED ( v_dimdate[DateId] )
            )
        RETURN
            v_dimdate[DateId] = _MaxDate
    )
RETURN
    SUMX ( _table, [InventoryCost] )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which works perfectly but I'm wondering if it can be simplyfied. I want it to simplify, because when I want to use this measure inside another one that sums those Inventory Cost values per month for last 3 months and I have wrong answers.&amp;nbsp;&lt;BR /&gt;Which means that this Inventory Cost measure works but if I call out this measure in the one below it shows wrong numbers (but other measures, more simply ones work).&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Rolling3Months = 
VAR _EndDate = MAX(v_dimdate[Date])
VAR _Dates =  DATESINPERIOD(v_dimdate[Date], _EndDate, -3, MONTH)
VAR _Cost = [Inventory Cost]
VAR _Inventory = SUMX(_Dates, CALCULATE(_Cost, ALL(v_dimdate[YearMonth])))
RETURN 
_Inventory &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a little bit stuck and would be super appreciated when someone would pointed out my mistakes/errors here.&lt;/P&gt;&lt;P&gt;I'm also providing sample power BI file with those.&amp;nbsp;&lt;BR /&gt;&lt;A href="https://we.tl/t-eQSOYHm1ft" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;https://we.tl/t-eQSOYHm1ft&lt;/SPAN&gt; &lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 19:34:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-for-last-days-of-month-per-each-category-how-to-simplify/m-p/2578504#M73913</guid>
      <dc:creator>BillyButcher</dc:creator>
      <dc:date>2022-06-14T19:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sum for last days of month per each category - how to simplify</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-for-last-days-of-month-per-each-category-how-to-simplify/m-p/2578934#M73936</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please try the below measure.&lt;/P&gt;
&lt;P&gt;I also attached the pbix file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Rolling3Months =
VAR _EndDate =
    MAX ( v_dimdate[Date] )
VAR _months =
    SUMMARIZE (
        FILTER (
            ALL ( v_dimdate ),
            v_dimdate[Date] IN DATESINPERIOD ( v_dimdate[Date], _EndDate, -3, MONTH )
        ),
        v_dimdate[YearMonth]
    )
VAR _Inventory =
    SUMX ( _months, [Inventory Cost] )
RETURN
    IF ( [Inventory Cost] &amp;lt;&amp;gt; BLANK (), _Inventory )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 02:33:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-for-last-days-of-month-per-each-category-how-to-simplify/m-p/2578934#M73936</guid>
      <dc:creator>Jihwan_Kim</dc:creator>
      <dc:date>2022-06-15T02:33:06Z</dc:date>
    </item>
  </channel>
</rss>

