<?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 Calculated Column with aggregate window partition in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4713035#M180505</link>
    <description>&lt;P&gt;In this article:&amp;nbsp;&lt;A href="https://www.statology.org/power-bi-z-score/" target="_blank" rel="noopener"&gt;How to Calculate Z-Scores in Power BI&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;He shows how to create Z-Scores with an calculated column. Very simple, But the STDDEV and AVERAGES are based on all rows of the table. I want to use a window partion and create the mean and std for only rows that have the same computer device name, same applicaiton, same location, etc.&lt;BR /&gt;&lt;BR /&gt;So instead of:&lt;BR /&gt;```&lt;/P&gt;&lt;LI-CODE lang="python"&gt;zzTokenWait = 
VAR data = 'App Stats'[WaitTimeMS]
VAR mean = AVERAGE('App Stats'[WaitTimeMS])
VAR std = STDEV.P('App Stats'[WaitTimeMS])
RETURN DIVIDE(data - mean, std, 0)&lt;/LI-CODE&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I want something for mean that looks more like this measure. But how to do it? Just cut and paste from the measure results in circular reference error:&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="javascript"&gt;VAR mean = CALCULATE(
			AVERAGE('App Stats'[WaitTimeMS]),
			FILTER(
				WINDOW(
					1,
					ABS,
					-1,
					ABS,
					'App Stats',
					ORDERBY('App Stats'[TimeStamp]),
					DEFAULT,
					PARTITIONBY(
						'App Stats'[AppName],
						'App Stats'[AppVersion],
						'App Stats'[BaseCode],
						'App Stats'[DeviceName]
					),
					MATCHBY('App Stats'[TimeStamp])
				),
				'App Stats'[AppName] = "AAD token broker plugin"
			)
		)​&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 29 May 2025 22:49:28 GMT</pubDate>
    <dc:creator>DoctorYSG</dc:creator>
    <dc:date>2025-05-29T22:49:28Z</dc:date>
    <item>
      <title>Calculated Column with aggregate window partition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4713035#M180505</link>
      <description>&lt;P&gt;In this article:&amp;nbsp;&lt;A href="https://www.statology.org/power-bi-z-score/" target="_blank" rel="noopener"&gt;How to Calculate Z-Scores in Power BI&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;He shows how to create Z-Scores with an calculated column. Very simple, But the STDDEV and AVERAGES are based on all rows of the table. I want to use a window partion and create the mean and std for only rows that have the same computer device name, same applicaiton, same location, etc.&lt;BR /&gt;&lt;BR /&gt;So instead of:&lt;BR /&gt;```&lt;/P&gt;&lt;LI-CODE lang="python"&gt;zzTokenWait = 
VAR data = 'App Stats'[WaitTimeMS]
VAR mean = AVERAGE('App Stats'[WaitTimeMS])
VAR std = STDEV.P('App Stats'[WaitTimeMS])
RETURN DIVIDE(data - mean, std, 0)&lt;/LI-CODE&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I want something for mean that looks more like this measure. But how to do it? Just cut and paste from the measure results in circular reference error:&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;LI-CODE lang="javascript"&gt;VAR mean = CALCULATE(
			AVERAGE('App Stats'[WaitTimeMS]),
			FILTER(
				WINDOW(
					1,
					ABS,
					-1,
					ABS,
					'App Stats',
					ORDERBY('App Stats'[TimeStamp]),
					DEFAULT,
					PARTITIONBY(
						'App Stats'[AppName],
						'App Stats'[AppVersion],
						'App Stats'[BaseCode],
						'App Stats'[DeviceName]
					),
					MATCHBY('App Stats'[TimeStamp])
				),
				'App Stats'[AppName] = "AAD token broker plugin"
			)
		)​&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2025 22:49:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4713035#M180505</guid>
      <dc:creator>DoctorYSG</dc:creator>
      <dc:date>2025-05-29T22:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Column with aggregate window partition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4713045#M180508</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="641031" data-lia-user-login="DoctorYSG" class="lia-mention lia-mention-user"&gt;DoctorYSG&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;To create a calculated column with an&amp;nbsp;&lt;SPAN&gt;aggregate window partition, try using the following DAX:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;zzTokenWait =
VAR windowRows =
    WINDOW(
        1, ABS, -1, ABS,
        'App Stats',
        ORDERBY('App Stats'[TimeStamp]),
        DEFAULT,
        PARTITIONBY(
            'App Stats'[AppName],
            'App Stats'[AppVersion],
            'App Stats'[BaseCode],
            'App Stats'[DeviceName]
        ),
        MATCHBY('App Stats'[TimeStamp])
    )
VAR filteredRows =
    FILTER(windowRows, 'App Stats'[AppName] = "AAD token broker plugin")

VAR mean = AVERAGEX(filteredRows, 'App Stats'[WaitTimeMS])
VAR std = STDEVX.P(filteredRows, 'App Stats'[WaitTimeMS])

RETURN
    DIVIDE('App Stats'[WaitTimeMS] - mean, std, 0)&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Samson&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2025 23:27:39 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4713045#M180508</guid>
      <dc:creator>SamsonTruong</dc:creator>
      <dc:date>2025-05-29T23:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Column with aggregate window partition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4713138#M180518</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="641031" data-lia-user-login="DoctorYSG" class="lia-mention lia-mention-user"&gt;DoctorYSG&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Z-Score with Partitioning in a Calculated Column:&lt;BR /&gt;Assuming your table is 'App Stats' and the relevant columns are below&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;WaitTimeMS (numeric value)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;AppName, AppVersion, BaseCode, DeviceName (partitioning columns)&lt;BR /&gt;&lt;/STRONG&gt;&lt;BR /&gt;Below is to write DAX expression for the calculated column:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;ZScore_Partitioned :=&lt;BR /&gt;VAR CurrentApp = 'App Stats'[AppName]&lt;BR /&gt;VAR CurrentVersion = 'App Stats'[AppVersion]&lt;BR /&gt;VAR CurrentBase = 'App Stats'[BaseCode]&lt;BR /&gt;VAR CurrentDevice = 'App Stats'[DeviceName]&lt;BR /&gt;VAR CurrentWait = 'App Stats'[WaitTimeMS]&lt;/P&gt;&lt;P&gt;VAR Mean =&lt;BR /&gt;CALCULATE(&lt;BR /&gt;AVERAGE('App Stats'[WaitTimeMS]),&lt;BR /&gt;FILTER(&lt;BR /&gt;'App Stats',&lt;BR /&gt;'App Stats'[AppName] = CurrentApp &amp;amp;&amp;amp;&lt;BR /&gt;'App Stats'[AppVersion] = CurrentVersion &amp;amp;&amp;amp;&lt;BR /&gt;'App Stats'[BaseCode] = CurrentBase &amp;amp;&amp;amp;&lt;BR /&gt;'App Stats'[DeviceName] = CurrentDevice&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;VAR StdDev =&lt;BR /&gt;CALCULATE(&lt;BR /&gt;STDEV.P('App Stats'[WaitTimeMS]),&lt;BR /&gt;FILTER(&lt;BR /&gt;'App Stats',&lt;BR /&gt;'App Stats'[AppName] = CurrentApp &amp;amp;&amp;amp;&lt;BR /&gt;'App Stats'[AppVersion] = CurrentVersion &amp;amp;&amp;amp;&lt;BR /&gt;'App Stats'[BaseCode] = CurrentBase &amp;amp;&amp;amp;&lt;BR /&gt;'App Stats'[DeviceName] = CurrentDevice&lt;BR /&gt;)&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;RETURN&lt;BR /&gt;DIVIDE(CurrentWait - Mean, StdDev, 0)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If this reply helped solve your problem, please consider clicking "Accept as Solution" so others can benefit too.&amp;nbsp;And if you found it useful, a quick "Kudos" is always appreciated, thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maruthi&amp;nbsp;&lt;/P&gt;&lt;P&gt;LinkedIn -&amp;nbsp;&lt;A href="http://www.linkedin.com/in/maruthi-siva-prasad/" target="_blank" rel="nofollow noopener noreferrer"&gt;http://www.linkedin.com/in/maruthi-siva-prasad/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;nbsp;&amp;nbsp;&lt;A href="https://x.com/maruthisp" target="_blank" rel="nofollow noopener noreferrer"&gt;Maruthi Siva Prasad - (@MaruthiSP) / X&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 02:29:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4713138#M180518</guid>
      <dc:creator>maruthisp</dc:creator>
      <dc:date>2025-05-30T02:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Column with aggregate window partition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4716038#M180633</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="641031" data-lia-user-login="DoctorYSG" class="lia-mention lia-mention-user"&gt;DoctorYSG&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jun 2025 05:31:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4716038#M180633</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2025-06-02T05:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Column with aggregate window partition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4720020#M180765</link>
      <description>&lt;P&gt;This looked really good, and I tried it, but I get the error shown below. I even added more factors to the MatchBy (AppName, AppVersion, BaseCode, and DeviceName) but it still gives the match error below. The solution from&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="526044" data-lia-user-login="maruthisp" class="lia-mention lia-mention-user"&gt;maruthisp&lt;/a&gt;&amp;nbsp;worked though. But I would still like to understand if your solution can be fixed, since it is usuable as a measure as well as a calculated column.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 15:22:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4720020#M180765</guid>
      <dc:creator>DoctorYSG</dc:creator>
      <dc:date>2025-06-04T15:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated Column with aggregate window partition</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4720203#M180772</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="641031" data-lia-user-login="DoctorYSG" class="lia-mention lia-mention-user"&gt;DoctorYSG&lt;/a&gt;&amp;nbsp;, Glad to hear the solution from&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="526044" data-lia-user-login="maruthisp" class="lia-mention lia-mention-user"&gt;maruthisp&lt;/a&gt;&amp;nbsp;worked!&lt;BR /&gt;&lt;BR /&gt;Here is a fix for my solution. As a note, please replace 'App Stats'[Id] with the unique identifier in your table:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;zzTokenWait =
VAR windowRows =
    WINDOW(
        1, ABS, -1, ABS,
        'App Stats',
        ORDERBY('App Stats'[TimeStamp]),
        DEFAULT,
        PARTITIONBY(
            'App Stats'[AppName],
            'App Stats'[AppVersion],
            'App Stats'[BaseCode],
            'App Stats'[DeviceName]
        ),
        MATCHBY('App Stats'[TimeStamp], 'App Stats'[Id]) -- replace 'App Stats'[Id] with the unique identifier in your table
    )
VAR filteredRows =
    FILTER(windowRows, 'App Stats'[AppName] = "AAD token broker plugin")

VAR mean = AVERAGEX(filteredRows, 'App Stats'[WaitTimeMS])
VAR std = STDEVX.P(filteredRows, 'App Stats'[WaitTimeMS])

RETURN
    DIVIDE('App Stats'[WaitTimeMS] - mean, std, 0)&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 18:01:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-Column-with-aggregate-window-partition/m-p/4720203#M180772</guid>
      <dc:creator>SamsonTruong</dc:creator>
      <dc:date>2025-06-04T18:01:02Z</dc:date>
    </item>
  </channel>
</rss>

