<?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 DAX measure to calculate sales, filtering by default the last 12 months in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-measure-to-calculate-sales-filtering-by-default-the-last-12/m-p/3592252#M138706</link>
    <description>&lt;P&gt;In Power BI, I need a DAX measure to calculate sales, filtering, by default, the last 12 months, however, if there is an external filter in the calendar table, the sales value to be returned must respect the external filter, if there is no external filter in the calendar table then the value to return must be the sales corresponding to the last 12 months. In the calendar table there is a column that identifies the last 12 months where the month that is part of the last 12 months is marked as 1 and the other months as 0. The name of this column is "[Last 12 Months]".&lt;/P&gt;&lt;P&gt;The DAX measure below partially meets these requirements, however, when performing an external filter on the calendar table that is outside the range of the last 12 months, the value returned is zero and this needs to be corrected so that if there is an external filter on the calendar table, the value returned must match the applied filter.&lt;/P&gt;&lt;P&gt;DAX...&lt;BR /&gt;IF(&lt;BR /&gt;NOT ISFILTERED('dCalendar'),&lt;BR /&gt;CALCULATE(&lt;BR /&gt;[USD Sales],&lt;BR /&gt;ALL('dCalendar'), -- Added to remove existing filters in the "dCalendar" table&lt;BR /&gt;'dCalendar'[Last 12 Months] = 1&lt;BR /&gt;),&lt;BR /&gt;CALCULATE(&lt;BR /&gt;[USD Sales],&lt;BR /&gt;'dCalendar',&lt;BR /&gt;'dCalendar'[Last 12 Months] = 1&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 19:55:22 GMT</pubDate>
    <dc:creator>Rai_BI</dc:creator>
    <dc:date>2023-12-19T19:55:22Z</dc:date>
    <item>
      <title>DAX measure to calculate sales, filtering by default the last 12 months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-measure-to-calculate-sales-filtering-by-default-the-last-12/m-p/3592252#M138706</link>
      <description>&lt;P&gt;In Power BI, I need a DAX measure to calculate sales, filtering, by default, the last 12 months, however, if there is an external filter in the calendar table, the sales value to be returned must respect the external filter, if there is no external filter in the calendar table then the value to return must be the sales corresponding to the last 12 months. In the calendar table there is a column that identifies the last 12 months where the month that is part of the last 12 months is marked as 1 and the other months as 0. The name of this column is "[Last 12 Months]".&lt;/P&gt;&lt;P&gt;The DAX measure below partially meets these requirements, however, when performing an external filter on the calendar table that is outside the range of the last 12 months, the value returned is zero and this needs to be corrected so that if there is an external filter on the calendar table, the value returned must match the applied filter.&lt;/P&gt;&lt;P&gt;DAX...&lt;BR /&gt;IF(&lt;BR /&gt;NOT ISFILTERED('dCalendar'),&lt;BR /&gt;CALCULATE(&lt;BR /&gt;[USD Sales],&lt;BR /&gt;ALL('dCalendar'), -- Added to remove existing filters in the "dCalendar" table&lt;BR /&gt;'dCalendar'[Last 12 Months] = 1&lt;BR /&gt;),&lt;BR /&gt;CALCULATE(&lt;BR /&gt;[USD Sales],&lt;BR /&gt;'dCalendar',&lt;BR /&gt;'dCalendar'[Last 12 Months] = 1&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 19:55:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-measure-to-calculate-sales-filtering-by-default-the-last-12/m-p/3592252#M138706</guid>
      <dc:creator>Rai_BI</dc:creator>
      <dc:date>2023-12-19T19:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: DAX measure to calculate sales, filtering by default the last 12 months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-measure-to-calculate-sales-filtering-by-default-the-last-12/m-p/3592732#M138725</link>
      <description>&lt;P&gt;Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.&lt;/P&gt;
&lt;P&gt;Please check the below picture and the attached pbix file.&lt;/P&gt;
&lt;P&gt;I hope the below can provide some ideas on how to create a solution for your semantic model.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&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;LI-CODE lang="markup"&gt;expected result measure: =
VAR _nofilterdayscount =
    CALCULATE ( COUNTROWS ( dCalendar ), REMOVEFILTERS () )
VAR _filterdayscount =
    CALCULATE ( COUNTROWS ( dCalendar ), ALLSELECTED ( dCalendar ) )
VAR _qty =
    SUM ( Sales[Quantity] )
VAR _qtylast12months =
    CALCULATE ( SUM ( Sales[Quantity] ), dCalendar[Last 12 Months] = 1 )
RETURN
    IF ( _nofilterdayscount = _filterdayscount, _qtylast12months, _qty )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 04:05:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-measure-to-calculate-sales-filtering-by-default-the-last-12/m-p/3592732#M138725</guid>
      <dc:creator>Jihwan_Kim</dc:creator>
      <dc:date>2023-12-20T04:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: DAX measure to calculate sales, filtering by default the last 12 months</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-measure-to-calculate-sales-filtering-by-default-the-last-12/m-p/3594085#M138849</link>
      <description>&lt;P&gt;Thank you very much!! This was exactly what i was looking for&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 13:59:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-measure-to-calculate-sales-filtering-by-default-the-last-12/m-p/3594085#M138849</guid>
      <dc:creator>Rai_BI</dc:creator>
      <dc:date>2023-12-20T13:59:00Z</dc:date>
    </item>
  </channel>
</rss>

