<?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: Previous 3 day average line graph in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294469#M170442</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="857546" data-lia-user-login="yuvan29" class="lia-mention lia-mention-user"&gt;yuvan29&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New Measure&lt;/P&gt;&lt;PRE&gt;Average Calls Last 3 Days = &lt;BR /&gt;VAR SelectedTime = SELECTEDVALUE('YourTable'[Time]) &lt;BR /&gt;VAR SelectedDate = SELECTEDVALUE('YourTable'[Date]) &lt;BR /&gt;&lt;BR /&gt;RETURN&lt;BR /&gt;AVERAGEX(&lt;BR /&gt;DATESINPERIOD(&lt;BR /&gt;'YourTable'[Date], &lt;BR /&gt;SelectedDate, &lt;BR /&gt;-3, &lt;BR /&gt;DAY&lt;BR /&gt;),&lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM('YourTable'[NumberOfCalls]), &lt;BR /&gt;'YourTable'[Time] = SelectedTime &lt;BR /&gt;)&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;Add a Line Chart&lt;/P&gt;&lt;P&gt;Put your Time on the X-axis.&lt;/P&gt;&lt;P&gt;Use the measure Average Calls Last 3 Days for the Y-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-unicode-emoji" title=":love_letter:"&gt;💌&lt;/span&gt; If this helped, a Kudos &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; or Solution mark would be great! &lt;span class="lia-unicode-emoji" title=":party_popper:"&gt;🎉&lt;/span&gt;&lt;/STRONG&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Kedar&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/kedar-pande" target="_blank" rel="noopener"&gt;Connect on LinkedIn&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Nov 2024 04:21:21 GMT</pubDate>
    <dc:creator>Kedar_Pande</dc:creator>
    <dc:date>2024-11-21T04:21:21Z</dc:date>
    <item>
      <title>Previous 3 day average line graph</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294144#M170426</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need some help in creating a measure that caluclates the average value at a certain time for the past 3 days. In my current line graph, I've got different times of the day on the x-axis and the number of calls on the y-axis. I also have a filter on the visual that selects which day to show the data for.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;For e.g. lets say the line graph above is filtered for the day of 5th November 2024. The datapoint on the average line graph at 9am will look at the number of calls at 9am on the 4th November, number of calls at 9am on the 3rd November and number of calls at 9am on the 2nd November and find the average of these numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate any help I can get, thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 00:07:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294144#M170426</guid>
      <dc:creator>yuvan29</dc:creator>
      <dc:date>2024-11-21T00:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Previous 3 day average line graph</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294325#M170432</link>
      <description>&lt;P&gt;&lt;FONT&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="857546" data-lia-user-login="yuvan29" class="lia-mention lia-mention-user"&gt;yuvan29&lt;/a&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Measure can only return one value at a date point, so I create 4 measures.&lt;/P&gt;
&lt;P&gt;Here's the sample:&lt;/P&gt;
&lt;P&gt;Table:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Last day = 
	VAR _currentTime = MAX('Table 2'[Time])
	VAR _today = DATE(YEAR(MAX('Table'[Date\Time])), MONTH(MAX('Table'[Date\Time])), DAY(MAX('Table'[Date\Time])))
	VAR _previousday = CALCULATE(
		MAX('Table'[Date\Time].[Date]),
		FILTER(
			ALL('Table'),
			DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) &amp;lt; _today
		)
	)
	RETURN
		CALCULATE(
			SUM('Table'[Values]),
			FILTER(
				ALL('Table'),
				TIME(
					HOUR('Table'[Date\Time]),
					MINUTE('Table'[Date\Time]),
					SECOND('Table'[Date\Time])
				) = _currentTime &amp;amp;&amp;amp; DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) = _previousday
			)
		)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Last 2 day = 
	VAR _currentTime = MAX('Table 2'[Time])
	VAR _today = DATE(YEAR(MAX('Table'[Date\Time])), MONTH(MAX('Table'[Date\Time])), DAY(MAX('Table'[Date\Time])))
	VAR _previousday = CALCULATE(
		MAX('Table'[Date\Time].[Date]),
		FILTER(
			ALL('Table'),
			DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) &amp;lt; _today
		)
	)
	VAR _last2day = CALCULATE(
		MAX('Table'[Date\Time].[Date]),
		FILTER(
			ALL('Table'),
			DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) &amp;lt; _previousday
		)
	)
	RETURN
		CALCULATE(
			SUM('Table'[Values]),
			FILTER(
				ALL('Table'),
				TIME(
					HOUR('Table'[Date\Time]),
					MINUTE('Table'[Date\Time]),
					SECOND('Table'[Date\Time])
				) = _currentTime &amp;amp;&amp;amp; DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) = _last2day
			)
		)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Last 3 day = 
	VAR _currentTime = MAX('Table 2'[Time])
	VAR _today = DATE(YEAR(MAX('Table'[Date\Time])), MONTH(MAX('Table'[Date\Time])), DAY(MAX('Table'[Date\Time])))
	VAR _previousday = CALCULATE(
		MAX('Table'[Date\Time].[Date]),
		FILTER(
			ALL('Table'),
			DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) &amp;lt; _today
		)
	)
	VAR _last2day = CALCULATE(
		MAX('Table'[Date\Time].[Date]),
		FILTER(
			ALL('Table'),
			DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) &amp;lt; _previousday
		)
	)
    VAR _last3day = CALCULATE(
		MAX('Table'[Date\Time].[Date]),
		FILTER(
			ALL('Table'),
			DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) &amp;lt; _last2day
		)
	)
	RETURN
		CALCULATE(
			SUM('Table'[Values]),
			FILTER(
				ALL('Table'),
				TIME(
					HOUR('Table'[Date\Time]),
					MINUTE('Table'[Date\Time]),
					SECOND('Table'[Date\Time])
				) = _currentTime &amp;amp;&amp;amp; DATE(YEAR('Table'[Date\Time]), MONTH('Table'[Date\Time]), DAY('Table'[Date\Time])) = _last3day
			)
		)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;AVG = 
	VAR _Today = IF(
		'Table'[Today] &amp;lt;&amp;gt; BLANK(),
		1,
		0
	)
	VAR _Previousday = IF(
		'Table'[Last day] &amp;lt;&amp;gt; BLANK(),
		1,
		0
	)
	VAR _Last2day = IF(
		'Table'[Last 2 day] &amp;lt;&amp;gt; BLANK(),
		1,
		0
	)
	RETURN
		([Last 2 day] + [Last day] + [Today]) / (_Last2day + _Previousday + _Today)&lt;/LI-CODE&gt;
&lt;P&gt;The result is as follow:&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;Best Regards&lt;/P&gt;
&lt;P&gt;Zhengdong Xu&lt;BR /&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt;&lt;EM&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 02:37:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294325#M170432</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-11-21T02:37:17Z</dc:date>
    </item>
    <item>
      <title>Re: Previous 3 day average line graph</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294469#M170442</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="857546" data-lia-user-login="yuvan29" class="lia-mention lia-mention-user"&gt;yuvan29&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;New Measure&lt;/P&gt;&lt;PRE&gt;Average Calls Last 3 Days = &lt;BR /&gt;VAR SelectedTime = SELECTEDVALUE('YourTable'[Time]) &lt;BR /&gt;VAR SelectedDate = SELECTEDVALUE('YourTable'[Date]) &lt;BR /&gt;&lt;BR /&gt;RETURN&lt;BR /&gt;AVERAGEX(&lt;BR /&gt;DATESINPERIOD(&lt;BR /&gt;'YourTable'[Date], &lt;BR /&gt;SelectedDate, &lt;BR /&gt;-3, &lt;BR /&gt;DAY&lt;BR /&gt;),&lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM('YourTable'[NumberOfCalls]), &lt;BR /&gt;'YourTable'[Time] = SelectedTime &lt;BR /&gt;)&lt;BR /&gt;)&lt;/PRE&gt;&lt;P&gt;Add a Line Chart&lt;/P&gt;&lt;P&gt;Put your Time on the X-axis.&lt;/P&gt;&lt;P&gt;Use the measure Average Calls Last 3 Days for the Y-axis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;span class="lia-unicode-emoji" title=":love_letter:"&gt;💌&lt;/span&gt; If this helped, a Kudos &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; or Solution mark would be great! &lt;span class="lia-unicode-emoji" title=":party_popper:"&gt;🎉&lt;/span&gt;&lt;/STRONG&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Kedar&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/kedar-pande" target="_blank" rel="noopener"&gt;Connect on LinkedIn&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 04:21:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294469#M170442</guid>
      <dc:creator>Kedar_Pande</dc:creator>
      <dc:date>2024-11-21T04:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Previous 3 day average line graph</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294616#M170450</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="857546" data-lia-user-login="yuvan29" class="lia-mention lia-mention-user"&gt;yuvan29&lt;/a&gt;&amp;nbsp;，&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Supposing you have a data table like this:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can try to plot a visual with time column and a measure like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Rolling 3d Avg = 
VAR _date = SELECTEDVALUE(data[date])
VAR _last3d = 
TOPN(
    3,
    FILTER(ALL(data[Date]), data[date]&amp;lt;_date),
    data[date]
)
VAR _3dtotal =
CALCULATE(
    SUM(data[value]),
    _last3d
)
VAR _result = DIVIDE(_3dtotal, COUNTROWS(_last3d))
RETURN _result&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it worked like this:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please find more info in the attached file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;p.s.:&lt;/P&gt;
&lt;P&gt;1. If more info could be provided, the code could be further simplified, like in the attachment.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. With dedicated calendar tables, you will also find Time Intelligence functions like DATESINPERIOD very handy for such cases.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 06:24:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Previous-3-day-average-line-graph/m-p/4294616#M170450</guid>
      <dc:creator>FreemanZ</dc:creator>
      <dc:date>2024-11-21T06:24:20Z</dc:date>
    </item>
  </channel>
</rss>

