<?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: Calculating value differences for each week in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1410229#M26120</link>
    <description>&lt;P&gt;Here is one way to do this one to get the result below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;First you need to add a column in query or with a DAX column to get the weeknumber as an integer.&amp;nbsp; You can then use these measure expressions (they differ only in the Return part).&amp;nbsp; The IF in the Return of the New Pass measure is to prevent a result of 2 showing in WW35.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;New Pass =
VAR thisweek =
    MAX ( Availability[WeekNumber] )
VAR summary =
    ADDCOLUMNS (
        VALUES ( Availability[Machine] ),
        "@ThisWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                Availability[WeekNumber] = thisweek
            ) + 0,
        "@LastWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                ALL (
                    Availability[WeekNumber],
                    Availability[WorkWeek]
                ),
                Availability[WeekNumber] = thisweek - 1
            ) + 0
    )
RETURN
    IF (
        thisweek
            = CALCULATE (
                MIN ( Availability[WeekNumber] ),
                ALL ( Availability )
            ),
        BLANK (),
        COUNTROWS (
            FILTER (
                summary,
                [@ThisWeek] - [@LastWeek] = 1
            )
        )
    )

New Fail =
VAR thisweek =
    MAX ( Availability[WeekNumber] )
VAR summary =
    ADDCOLUMNS (
        VALUES ( Availability[Machine] ),
        "@ThisWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                Availability[WeekNumber] = thisweek
            ) + 0,
        "@LastWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                ALL (
                    Availability[WeekNumber],
                    Availability[WorkWeek]
                ),
                Availability[WeekNumber] = thisweek - 1
            ) + 0
    )
RETURN
    COUNTROWS (
        FILTER (
            summary,
            [@ThisWeek] - [@LastWeek] = -1
        )
    )

Steady =
VAR thisweek =
    MAX ( Availability[WeekNumber] )
VAR summary =
    ADDCOLUMNS (
        VALUES ( Availability[Machine] ),
        "@ThisWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                Availability[WeekNumber] = thisweek
            ) + 0,
        "@LastWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                ALL (
                    Availability[WeekNumber],
                    Availability[WorkWeek]
                ),
                Availability[WeekNumber] = thisweek - 1
            ) + 0
    )
RETURN
    COUNTROWS (
        FILTER (
            summary,
            [@ThisWeek] - [@LastWeek] = 0
                &amp;amp;&amp;amp; [@ThisWeek] = 1
        )
    )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Pat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Oct 2020 18:38:59 GMT</pubDate>
    <dc:creator>mahoneypat</dc:creator>
    <dc:date>2020-10-02T18:38:59Z</dc:date>
    <item>
      <title>Calculating value differences for each week</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1400471#M25767</link>
      <description>&lt;P&gt;I have some 'availability' numbers (a percentage) for a bunch of machines on a weekly basis. My raw CSV data looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;Machine,WW,Availability
A,WW35,0.9
B,WW35,0.95
C,WW35,1
D,WW35,0.87
A,WW36,1
B,WW36,1
C,WW36,0.84
D,WW36,0.94
A,WW37,0.75
B,WW37,0.98
C,WW37,0.91
D,WW37,0.89
A,WW38,1
B,WW38,0.88
C,WW38,0.99
D,WW38,0.95&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data source is updated weekly and new Work Week (WW) availability data is added for each machine. A machine is deemed 'Pass' if the availability for that week is &amp;gt; 90%. I calculate the 'Pass' measure as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Pass = 
VAR varCount = CALCULATE(COUNTA(data[Availability]), data[Availability] &amp;gt; 0.9)
RETURN
IF(varCount = BLANK(), 0, varCount)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pass count for each machine for each week, displayed in a matrix, looks like this (given above data):&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, I want to calculate some figures for these pass values for each machine. My actual needs are a bit complex, but few of the most basic things I wanted calculated are shown below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;New Pass&lt;BR /&gt;Number of total machines for each week that passed, but failed previous week.&lt;/LI&gt;&lt;LI&gt;New Fail&lt;BR /&gt;Number of total machines for each week that failed, but passed previous week.&lt;/LI&gt;&lt;LI&gt;Steady&lt;BR /&gt;Number of total machines for each week that the condition didn't change.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;To better illustrate, I put my desired results in an Excel file:&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;P&gt;As mentioned at the beginning of the post, my source CSV is updated with new data each week, so as time goes on I will have more [WW] columns added in my PowerBI matrix. Given this I don't quite know how I can calculate the above values dynamically without hardcoding anything. Is this possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 23:43:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1400471#M25767</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-09-28T23:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating value differences for each week</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1409621#M26100</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt; - this might be better off doing a PowerQuery/M creation of columns showing this week's Pass/Fail and Last Week's Pass/Fail. May want to post in that forum.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1522" data-lia-user-login="ImkeF" class="lia-mention lia-mention-user"&gt;ImkeF&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="12123" data-lia-user-login="vanessafvg" class="lia-mention lia-mention-user"&gt;vanessafvg&lt;/a&gt; &amp;nbsp;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="32447" data-lia-user-login="tex628" class="lia-mention lia-mention-user"&gt;tex628&lt;/a&gt; &amp;nbsp;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="226208" data-lia-user-login="mahoneypat" class="lia-mention lia-mention-user"&gt;mahoneypat&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="24715" data-lia-user-login="edhans" class="lia-mention lia-mention-user"&gt;edhans&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 13:23:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1409621#M26100</guid>
      <dc:creator>dedelman_clng</dc:creator>
      <dc:date>2020-10-02T13:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating value differences for each week</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1410229#M26120</link>
      <description>&lt;P&gt;Here is one way to do this one to get the result below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;First you need to add a column in query or with a DAX column to get the weeknumber as an integer.&amp;nbsp; You can then use these measure expressions (they differ only in the Return part).&amp;nbsp; The IF in the Return of the New Pass measure is to prevent a result of 2 showing in WW35.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;New Pass =
VAR thisweek =
    MAX ( Availability[WeekNumber] )
VAR summary =
    ADDCOLUMNS (
        VALUES ( Availability[Machine] ),
        "@ThisWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                Availability[WeekNumber] = thisweek
            ) + 0,
        "@LastWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                ALL (
                    Availability[WeekNumber],
                    Availability[WorkWeek]
                ),
                Availability[WeekNumber] = thisweek - 1
            ) + 0
    )
RETURN
    IF (
        thisweek
            = CALCULATE (
                MIN ( Availability[WeekNumber] ),
                ALL ( Availability )
            ),
        BLANK (),
        COUNTROWS (
            FILTER (
                summary,
                [@ThisWeek] - [@LastWeek] = 1
            )
        )
    )

New Fail =
VAR thisweek =
    MAX ( Availability[WeekNumber] )
VAR summary =
    ADDCOLUMNS (
        VALUES ( Availability[Machine] ),
        "@ThisWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                Availability[WeekNumber] = thisweek
            ) + 0,
        "@LastWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                ALL (
                    Availability[WeekNumber],
                    Availability[WorkWeek]
                ),
                Availability[WeekNumber] = thisweek - 1
            ) + 0
    )
RETURN
    COUNTROWS (
        FILTER (
            summary,
            [@ThisWeek] - [@LastWeek] = -1
        )
    )

Steady =
VAR thisweek =
    MAX ( Availability[WeekNumber] )
VAR summary =
    ADDCOLUMNS (
        VALUES ( Availability[Machine] ),
        "@ThisWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                Availability[WeekNumber] = thisweek
            ) + 0,
        "@LastWeek",
            CALCULATE (
                COUNT ( Availability[Machine] ),
                Availability[Availability] &amp;gt; 0.9,
                ALL (
                    Availability[WeekNumber],
                    Availability[WorkWeek]
                ),
                Availability[WeekNumber] = thisweek - 1
            ) + 0
    )
RETURN
    COUNTROWS (
        FILTER (
            summary,
            [@ThisWeek] - [@LastWeek] = 0
                &amp;amp;&amp;amp; [@ThisWeek] = 1
        )
    )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Pat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 18:38:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1410229#M26120</guid>
      <dc:creator>mahoneypat</dc:creator>
      <dc:date>2020-10-02T18:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating value differences for each week</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1416130#M26320</link>
      <description>&lt;P&gt;Wow that's pretty complicated. But how do you set a measure as 'Rows' in your Matrix? Power BI won't let me do that.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 17:54:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-value-differences-for-each-week/m-p/1416130#M26320</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-10-06T17:54:21Z</dc:date>
    </item>
  </channel>
</rss>

