<?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 Problems getting previous month averages in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750591#M2699</link>
    <description>&lt;P&gt;I have one table (Overtime) with Activity_date and Activity_hours.&amp;nbsp; I have a date table (Date) which has a relationship between activity_date and the date column of the date table.&amp;nbsp; I am trying to find the average number of weekend hours.&lt;/P&gt;&lt;P&gt;I've tried a few different approaches, but below is the most recent.&amp;nbsp; It works up to the point of adding the PreviousMonth portion.&amp;nbsp; Once I add that I only get blank.&amp;nbsp; Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Test = calculate(divide(sum(Overtime[Activity_Hours]),DISTINCTCOUNT('Overtime'[Activity_Date]),0),WEEKDAY(Overtime[Activity_Date],2)&amp;gt;5,PREVIOUSMONTH(Overtime[Activity_Date]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Sat, 27 Jul 2019 23:24:57 GMT</pubDate>
    <dc:creator>PaulBI</dc:creator>
    <dc:date>2019-07-27T23:24:57Z</dc:date>
    <item>
      <title>Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750591#M2699</link>
      <description>&lt;P&gt;I have one table (Overtime) with Activity_date and Activity_hours.&amp;nbsp; I have a date table (Date) which has a relationship between activity_date and the date column of the date table.&amp;nbsp; I am trying to find the average number of weekend hours.&lt;/P&gt;&lt;P&gt;I've tried a few different approaches, but below is the most recent.&amp;nbsp; It works up to the point of adding the PreviousMonth portion.&amp;nbsp; Once I add that I only get blank.&amp;nbsp; Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Test = calculate(divide(sum(Overtime[Activity_Hours]),DISTINCTCOUNT('Overtime'[Activity_Date]),0),WEEKDAY(Overtime[Activity_Date],2)&amp;gt;5,PREVIOUSMONTH(Overtime[Activity_Date]))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 27 Jul 2019 23:24:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750591#M2699</guid>
      <dc:creator>PaulBI</dc:creator>
      <dc:date>2019-07-27T23:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750617#M2705</link>
      <description>&lt;P&gt;how many months back do you want to average? do you want to average per month or just to have average umber of hours per weekend day?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;having some sample rows from the overtime table in copiable format would help me work faster as well, like this&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 96pt;" border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" style="height: 15.0pt; width: 48pt;"&gt;Column1&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;Column2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;A&lt;/TD&gt;
&lt;TD align="right"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" style="height: 15.0pt;"&gt;B&lt;/TD&gt;
&lt;TD align="right"&gt;2.5&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sun, 28 Jul 2019 02:07:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750617#M2705</guid>
      <dc:creator>Stachu</dc:creator>
      <dc:date>2019-07-28T02:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750618#M2706</link>
      <description>&lt;P&gt;Right now I'm only looking for the month before the latest date.&amp;nbsp; I have a monthly average with no months specifically filtered that I can plot and break out by month, but when I try to only pick the last month for use in another measure I run into an issue.&amp;nbsp; The data refreshes once per week so typically it will be last month in relation to today with a few expections.&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a sample of the data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Activity_Date&lt;/TD&gt;&lt;TD&gt;Activity_Hours&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunday, June 30, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunday, June 30, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Friday, June 28, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Thursday, June 27, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Tuesday, June 25, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunday, July 21, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Saturday, July 20, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Saturday, July 06, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Friday, July 05, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Thursday, July 04, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Wednesday, July 03, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Wednesday, July 03, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Tuesday, July 02, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Monday, July 01, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunday, June 30, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Saturday, June 29, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Friday, June 28, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Thursday, June 27, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Thursday, June 27, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Wednesday, June 26, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Tuesday, June 25, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Monday, June 24, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Tuesday, May 28, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Monday, May 27, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunday, May 26, 2019&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sunday, May 26, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Saturday, May 25, 2019&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 28 Jul 2019 02:40:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750618#M2706</guid>
      <dc:creator>PaulBI</dc:creator>
      <dc:date>2019-07-28T02:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750622#M2707</link>
      <description>&lt;P&gt;I'd use the Date table to modify the date filter context&lt;BR /&gt;so e.g. if this is your average:&lt;/P&gt;
&lt;PRE&gt;Avg = 
CALCULATE (
    DIVIDE (
        SUM ( Overtime[Activity_Hours] ),
        DISTINCTCOUNT ( 'Overtime'[Activity_Date] ),
        0
    ),
    KEEPFILTERS(WEEKDAY ( 'Calendar'[Date], 2 ) &amp;gt; 5)
)&lt;/PRE&gt;
&lt;P&gt;you can calculate previous month average like this:&lt;/P&gt;
&lt;PRE&gt;Avg Prev Month = 
CALCULATE(
    [Avg],
    PREVIOUSMONTH('Calendar'[Date])
    )&lt;/PRE&gt;
&lt;P&gt;which calculated the period in reference to the filter context in the Calendar table (here row determines specific month):&lt;BR /&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;you can notice that [Avg Prev Month] is empty on total - that's because there is no specific month reference&lt;/P&gt;
&lt;DIV style="border-radius: 1px; border: solid #CCCCCC 1px; background: #fafafa url('https://community.powerbi.com/t5/image/serverpage/image-id/86505i901712D27DD154D7/image-size/small?v...') no-repeat right 10px center; background-size: auto 60%;"&gt;Did I answer your question? &lt;STRONG style="margin-right: 100px;"&gt; Mark my post as a solution!&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;Proud to be a Datanaut!&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sun, 28 Jul 2019 03:34:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750622#M2707</guid>
      <dc:creator>Stachu</dc:creator>
      <dc:date>2019-07-28T03:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750702#M2715</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="10823" data-lia-user-login="Stachu" class="lia-mention lia-mention-user"&gt;Stachu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It fixed a lot of it but there is still one small part.&amp;nbsp; Thank you for your help so far.&amp;nbsp; When I create a table visual it shows that it works.&amp;nbsp; Now I'm using this information as an input into a projection.&amp;nbsp; I'm adding a column in the date table to project based on last month's numbers, what the rest of the month looks like but when I use the measures for that, I get numbers that don't match the table visualization.&amp;nbsp; I verified independantly in excel that the visual values are correct.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Forecasted = if('Date'[Dateswithdata]=false,if('Date'[Weekend?]=true,[Last Month Average Monthly Weekend Day Hours],[Last Month Average Monthly Weekday Hours]),BLANK())&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Correct Table Visual:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Column (forecasted) with incorrect numbers, using the same measure:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the information so far.&amp;nbsp; Also, for my own knowledge, can you explain why I needed to use the keepfilters function in the measure?&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jul 2019 16:31:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750702#M2715</guid>
      <dc:creator>PaulBI</dc:creator>
      <dc:date>2019-07-28T16:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750783#M2721</link>
      <description>&lt;P&gt;regarding KEEPFILTERS - as we use Calendar[Date] as a second argument for CALCULATE the filter context of that column is overwritten to show only weekends - all the weekends. Now we don't won't to show all of them, only the ones that match current filter context for month - that's why I added KEEPFILTERS&lt;BR /&gt;you can read more on CALCULATE here&lt;BR /&gt;&lt;A href="https://www.sqlbi.com/articles/filter-arguments-in-calculate/" target="_blank"&gt;https://www.sqlbi.com/articles/filter-arguments-in-calculate/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the filter context of Date in calculated column is the value in the row, so it calculates in reference to a single date. Other than that adding fact data to a dimension table is not a very elegant solution. Do you need forecast in the calculated column, or could it be in the measure or calculated table? How do you need to use it later? the values should be the same (avg for latest month with actual data) for all the future periods, correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="border-radius: 1px; border: solid #CCCCCC 1px; background: #fafafa url('https://community.powerbi.com/t5/image/serverpage/image-id/86505i901712D27DD154D7/image-size/small?v...') no-repeat right 10px center; background-size: auto 60%;"&gt;Did I answer your question? &lt;STRONG style="margin-right: 100px;"&gt; Mark my post as a solution!&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;Proud to be a Datanaut!&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sun, 28 Jul 2019 16:50:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750783#M2721</guid>
      <dc:creator>Stachu</dc:creator>
      <dc:date>2019-07-28T16:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750788#M2723</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="10823" data-lia-user-login="Stachu" class="lia-mention lia-mention-user"&gt;Stachu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the graphic I'm trying to create, where the projected is using last month's average # of hours per weekday and weekend to project to the end of the month.&amp;nbsp; Right now the projection is being calculated by the measure 'Projected" (below) which uses the calculated column in the dates table in the picture in my earlier post (Date[Forecast]) but like I said, it is not actually relaying the true previous month average.&amp;nbsp; All the help so far is really appreciated.&amp;nbsp; If you have any insight into how better to do this would be appreciated too.&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Projected = 
if(SELECTEDVALUE('Date'[Dateswithdata])=FALSE(),calculate(sum(Overtime[Activity_Hours])+(sum('Date'[Forecasted])),DATESMTD('Date'[Date]),year('Date'[Date])&amp;gt;=year(TODAY()),month('Date'[Date])=month(today())),BLANK())&lt;/PRE&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Jul 2019 17:06:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750788#M2723</guid>
      <dc:creator>PaulBI</dc:creator>
      <dc:date>2019-07-28T17:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750836#M2732</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="10823" data-lia-user-login="Stachu" class="lia-mention lia-mention-user"&gt;Stachu&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you for all the help.&amp;nbsp; I really appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After a bunch of trial and error I think I figured out the overall solution.&amp;nbsp; I took the dax from the calculated column, shifted from a sum to a sumx and pasted all of it in the measure where I had the calculated column.&amp;nbsp; It looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Projected = 


if(SELECTEDVALUE('Date'[Dateswithdata])=FALSE(),calculate(sum(Overtime[Activity_Hours])+(sumx('Date',if('Date'[Dateswithdata]=false,if('Date'[Weekend?]=true,[Last Month Average Monthly Weekend Day Hours],[Last Month Average Monthly Weekday Hours]),BLANK()))),DATESMTD('Date'[Date]),year('Date'[Date])&amp;gt;=year(TODAY()),month('Date'[Date])=month(today())),BLANK())&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 00:05:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750836#M2732</guid>
      <dc:creator>PaulBI</dc:creator>
      <dc:date>2019-07-29T00:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problems getting previous month averages</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750848#M2735</link>
      <description>&lt;P&gt;glad you got it working :smileyhappy:&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 01:19:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Problems-getting-previous-month-averages/m-p/750848#M2735</guid>
      <dc:creator>Stachu</dc:creator>
      <dc:date>2019-07-29T01:19:31Z</dc:date>
    </item>
  </channel>
</rss>

