<?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: Get this week, last week and average last 4 weeks data based on selected week in slicer in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4007005#M156892</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="81736" data-lia-user-login="aduguid" class="lia-mention lia-mention-user"&gt;aduguid&lt;/a&gt;&amp;nbsp;Thanks. This already helps me out, but now I can't seem to make it work to have in the colums the week, last week and average and to have as rows the description of each value.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jun 2024 13:22:45 GMT</pubDate>
    <dc:creator>Nico_BE</dc:creator>
    <dc:date>2024-06-24T13:22:45Z</dc:date>
    <item>
      <title>Get this week, last week and average last 4 weeks data based on selected week in slicer</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4006931#M156890</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new to Power BI and hope that someone can answer my question.&lt;/P&gt;&lt;P&gt;This is the kind of data that is imported and this data will always start on the first of january untill the 31st december:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a matrix (or something else?) as followed, based on the week that is selected in a slicer.:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the goal is that when in the slicer "5" is selected (week 5), it will give the data of week 5 in "This week", the data of week 4 in "Last week" and the average of week 1 until 4 in "Last 4 weeks Avg".&lt;/P&gt;&lt;P&gt;This would than automaticly change when another week is selected in the slicer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this is clear as what I would like to achieve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2024 12:50:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4006931#M156890</guid>
      <dc:creator>Nico_BE</dc:creator>
      <dc:date>2024-06-24T12:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: Get this week, last week and average last 4 weeks data based on selected week in slicer</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4006947#M156891</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;Create "This Week" Measure:&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;This Week = 
VAR SelectedWeek = MAX('YourTable'[WeekNumber])
RETURN
CALCULATE(
    SUM('YourTable'[YourMetric]),
    'YourTable'[WeekNumber] = SelectedWeek
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;Create "Last Week" Measure:&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last Week = 
VAR SelectedWeek = MAX('YourTable'[WeekNumber])
RETURN
CALCULATE(
    SUM('YourTable'[YourMetric]),
    'YourTable'[WeekNumber] = SelectedWeek - 1
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;Create "Last 4 Weeks Avg" Measure:&lt;/STRONG&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Last 4 Weeks Avg = 
VAR SelectedWeek = MAX('YourTable'[WeekNumber])
RETURN
CALCULATE(
    AVERAGE('YourTable'[YourMetric]),
    'YourTable'[WeekNumber] &amp;gt;= SelectedWeek - 4 &amp;amp;&amp;amp; 'YourTable'[WeekNumber] &amp;lt; SelectedWeek
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2024 13:01:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4006947#M156891</guid>
      <dc:creator>aduguid</dc:creator>
      <dc:date>2024-06-24T13:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Get this week, last week and average last 4 weeks data based on selected week in slicer</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4007005#M156892</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="81736" data-lia-user-login="aduguid" class="lia-mention lia-mention-user"&gt;aduguid&lt;/a&gt;&amp;nbsp;Thanks. This already helps me out, but now I can't seem to make it work to have in the colums the week, last week and average and to have as rows the description of each value.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2024 13:22:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4007005#M156892</guid>
      <dc:creator>Nico_BE</dc:creator>
      <dc:date>2024-06-24T13:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Get this week, last week and average last 4 weeks data based on selected week in slicer</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4008266#M157353</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="81736" data-lia-user-login="aduguid" class="lia-mention lia-mention-user"&gt;aduguid&lt;/a&gt;&amp;nbsp;,Thanks for your quick reply, I will add more.&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="765002" data-lia-user-login="Nico_BE" class="lia-mention lia-mention-user"&gt;Nico_BE&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Do you want to create a matrix similar to the picture?Like this?&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;The Table data is shown below:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Please follow these steps:&lt;/P&gt;
&lt;P&gt;1.Enter the following data manually.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;2.Use the following DAX expression to create measures&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;This week = 
VAR _axtualOrPlan = SELECTEDVALUE(Table2[Row])
VAR _weeknumber = MAX('Table'[Week])
RETURN 
SWITCH(TRUE(),
_axtualOrPlan = "DL Actual",SUMX(FILTER('Table','Table'[Week] = _weeknumber),[DL Actual]),
_axtualOrPlan = "DL Plan",SUMX(FILTER('Table','Table'[Week] = _weeknumber),[DL Plan])
)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Last week = 
VAR _axtualOrPlan = SELECTEDVALUE(Table2[Row])
VAR _weeknumber = MAX('Table'[Week])
RETURN 
SWITCH(TRUE(),
_axtualOrPlan = "DL Actual",CALCULATE(SUMX(FILTER('Table','Table'[Week] = _weeknumber - 1),[DL Actual]),ALL('Table'[Week])),
_axtualOrPlan = "DL Plan",CALCULATE(SUMX(FILTER('Table','Table'[Week] = _weeknumber - 1),[DL Plan]),ALL('Table'[Week]))
)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Last 4 week av = 
VAR _axtualOrPlan = SELECTEDVALUE(Table2[Row])
VAR _weeknumber = MAX('Table'[Week])
RETURN 
SWITCH(TRUE(),
_axtualOrPlan = "DL Actual",CALCULATE(AVERAGEX(FILTER('Table','Table'[Week] &amp;gt;= _weeknumber - 4 &amp;amp;&amp;amp; 'Table'[Week] &amp;lt; _weeknumber),[DL Actual]),ALL('Table'[Week])),
_axtualOrPlan = "DL Plan",CALCULATE(AVERAGEX(FILTER('Table','Table'[Week] &amp;gt;= _weeknumber - 4 &amp;amp;&amp;amp; 'Table'[Week] &amp;lt; _weeknumber),[DL Plan]),ALL('Table'[Week]))
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3.Final output&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&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;</description>
      <pubDate>Tue, 25 Jun 2024 05:31:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Get-this-week-last-week-and-average-last-4-weeks-data-based-on/m-p/4008266#M157353</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-25T05:31:06Z</dc:date>
    </item>
  </channel>
</rss>

