<?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 Calculate a Measure Based on Date Filter in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-Measure-Based-on-Date-Filter/m-p/1542193#M30384</link>
    <description>&lt;P&gt;I am trying to calculate a measure based on my date filter in the report.&amp;nbsp; Here is the formula I am using to count the days between between the start and end date of the filter:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Count Days = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var start_Date=FIRSTDATE(ALLSELECTED('calendar_auto'[Date]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var end_Date=LASTDATE(ALLSELECTED('calendar_auto'[Date]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var current_Start=MIN('public inventory_binadjustment'[transaction_date_local])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var current_end=MAX('public inventory_binadjustment'[transaction_date_local])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;DATEDIFF(MAX(start_Date,current_Start),MIN(end_Date,current_end),DAY)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;It returns the correct amount of days.&amp;nbsp; My next step is to have another measure that calculates the average daily usage of each item in the table based on that amount of days.&amp;nbsp; In the example the days from the filter represents 182 days.&amp;nbsp; However, you can see in the table the "Count Days" is looking at the first and last dates for that specific item instead of the complete 182 days.&amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any suggestion on how I can get the measure to "Average Daily Usage" to calculate based on the first and last dates of the filter instead of just the days for that specific item?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 10 Dec 2020 05:02:52 GMT</pubDate>
    <dc:creator>cmac1</dc:creator>
    <dc:date>2020-12-10T05:02:52Z</dc:date>
    <item>
      <title>Calculate a Measure Based on Date Filter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-Measure-Based-on-Date-Filter/m-p/1542193#M30384</link>
      <description>&lt;P&gt;I am trying to calculate a measure based on my date filter in the report.&amp;nbsp; Here is the formula I am using to count the days between between the start and end date of the filter:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Count Days = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var start_Date=FIRSTDATE(ALLSELECTED('calendar_auto'[Date]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var end_Date=LASTDATE(ALLSELECTED('calendar_auto'[Date]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var current_Start=MIN('public inventory_binadjustment'[transaction_date_local])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var current_end=MAX('public inventory_binadjustment'[transaction_date_local])&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;DATEDIFF(MAX(start_Date,current_Start),MIN(end_Date,current_end),DAY)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;It returns the correct amount of days.&amp;nbsp; My next step is to have another measure that calculates the average daily usage of each item in the table based on that amount of days.&amp;nbsp; In the example the days from the filter represents 182 days.&amp;nbsp; However, you can see in the table the "Count Days" is looking at the first and last dates for that specific item instead of the complete 182 days.&amp;nbsp; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Any suggestion on how I can get the measure to "Average Daily Usage" to calculate based on the first and last dates of the filter instead of just the days for that specific item?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Dec 2020 05:02:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-Measure-Based-on-Date-Filter/m-p/1542193#M30384</guid>
      <dc:creator>cmac1</dc:creator>
      <dc:date>2020-12-10T05:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a Measure Based on Date Filter</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-Measure-Based-on-Date-Filter/m-p/1570986#M31297</link>
      <description>&lt;P&gt;whenever you see a behavior like that you need to think about the filter context. By default it only looks at the current "row". You need to use ALL() or ALLSELECTED() on your fact table (not the dates table) to expand the context according to your requirements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide sample data in usable format and show the expected outcome.&lt;/P&gt;</description>
      <pubDate>Sun, 27 Dec 2020 03:21:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-a-Measure-Based-on-Date-Filter/m-p/1570986#M31297</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2020-12-27T03:21:35Z</dc:date>
    </item>
  </channel>
</rss>

