<?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: How to find the last value for each group in a reporting period and count the average for these rows in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3439726#M130608</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="551429" data-lia-user-login="marypal" class="lia-mention lia-mention-user"&gt;marypal&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try code as below to create measures.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Avg Score = 
VAR _ReportDate =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR _GENERATE =
    GENERATE (
        VALUES ( 'Table 1'[activity_type] ),
        VALUES ( 'Table 1'[client_id] )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _GENERATE,
        "Score",
            VAR _MAXDATE =
                CALCULATE (
                    MAX ( 'Table 1'[activity_date] ),
                    FILTER (
                        'Table 1',
                        'Table 1'[activity_type] = EARLIER ( [activity_type] )
                            &amp;amp;&amp;amp; 'Table 1'[client_id] = EARLIER ( [client_id] )
                            &amp;amp;&amp;amp; 'Table 1'[activity_date] &amp;lt;= _ReportDate
                    )
                )
            RETURN
                CALCULATE (
                    SUM ( 'Table 1'[score] ),
                    FILTER (
                        'Table 1',
                        'Table 1'[activity_type] = EARLIER ( [activity_type] )
                            &amp;amp;&amp;amp; 'Table 1'[client_id] = EARLIER ( [client_id] )
                            &amp;amp;&amp;amp; 'Table 1'[activity_date] = _MAXDATE
                    )
                )
    )
RETURN
    AVERAGEX (
        FILTER ( _ADD1, [activity_type] = MAX ( 'Table 1'[activity_type] ) ),
        [Score]
    )&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Number of Clients = 
VAR _ReportDate =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR _GENERATE =
    GENERATE (
        VALUES ( 'Table 1'[activity_type] ),
        VALUES ( 'Table 1'[client_id] )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _GENERATE,
        "Score",
            VAR _MAXDATE =
                CALCULATE (
                    MAX ( 'Table 1'[activity_date] ),
                    FILTER (
                        'Table 1',
                        'Table 1'[activity_type] = EARLIER ( [activity_type] )
                            &amp;amp;&amp;amp; 'Table 1'[client_id] = EARLIER ( [client_id] )
                            &amp;amp;&amp;amp; 'Table 1'[activity_date] &amp;lt;= _ReportDate
                    )
                )
            RETURN
                CALCULATE (
                    SUM ( 'Table 1'[score] ),
                    FILTER (
                        'Table 1',
                        'Table 1'[activity_type] = EARLIER ( [activity_type] )
                            &amp;amp;&amp;amp; 'Table 1'[client_id] = EARLIER ( [client_id] )
                            &amp;amp;&amp;amp; 'Table 1'[activity_date] = _MAXDATE
                    )
                )
    )
RETURN
COUNTX(FILTER(_ADD1,[activity_type] = MAX('Table 1'[activity_type]) &amp;amp;&amp;amp; [Score]&amp;lt;&amp;gt;BLANK()),[activity_type])&lt;/LI-CODE&gt;
&lt;P&gt;Result is as below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2023 09:50:15 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-09-20T09:50:15Z</dc:date>
    <item>
      <title>How to find the last value for each group in a reporting period and count the average for these rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3430678#M130060</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could anybody help me with my task, please.&lt;/P&gt;&lt;P&gt;I am using a &lt;STRONG&gt;DirectQuery&lt;/STRONG&gt; mode.&lt;BR /&gt;My Table 1 contains columns:&lt;BR /&gt;-&amp;nbsp;activity_type&lt;/P&gt;&lt;P&gt;-&amp;nbsp;client_id&lt;/P&gt;&lt;P&gt;-&amp;nbsp;activity_id&lt;/P&gt;&lt;P&gt;-&amp;nbsp;activity_date&lt;/P&gt;&lt;P&gt;-&amp;nbsp;score&lt;BR /&gt;I have a reporting date, the last date of a month, that we choose using a slicer.&amp;nbsp;&lt;BR /&gt;I need to find for each client_id, activity_type the last activity_id and corresponding score such that activity_date&amp;lt;=reporting_date and display that in Table 2.&lt;BR /&gt;After that we need to count for each activity_type the number of clients for which score is not null and find the average score.&lt;BR /&gt;Would be greatful for any hints&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2023 10:17:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3430678#M130060</guid>
      <dc:creator>marypal</dc:creator>
      <dc:date>2023-09-14T10:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the last value for each group in a reporting period and count the average for these rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3434339#M130262</link>
      <description>&lt;LI-CODE lang="markup"&gt;I need to find for each client_id, activity_type the last activity_id and corresponding score&lt;/LI-CODE&gt;
&lt;P&gt;The max([activity _id]) is not a problem.&amp;nbsp; However the "corresponding score"&amp;nbsp; is, as you cannot easily aggregate that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will likely need to use table variables&amp;nbsp; in your measure and filter that table variable.&amp;nbsp; Not sure how feasible that is in Direct Query mode.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Sep 2023 22:33:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3434339#M130262</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2023-09-16T22:33:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the last value for each group in a reporting period and count the average for these rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3439726#M130608</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="551429" data-lia-user-login="marypal" class="lia-mention lia-mention-user"&gt;marypal&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try code as below to create measures.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Avg Score = 
VAR _ReportDate =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR _GENERATE =
    GENERATE (
        VALUES ( 'Table 1'[activity_type] ),
        VALUES ( 'Table 1'[client_id] )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _GENERATE,
        "Score",
            VAR _MAXDATE =
                CALCULATE (
                    MAX ( 'Table 1'[activity_date] ),
                    FILTER (
                        'Table 1',
                        'Table 1'[activity_type] = EARLIER ( [activity_type] )
                            &amp;amp;&amp;amp; 'Table 1'[client_id] = EARLIER ( [client_id] )
                            &amp;amp;&amp;amp; 'Table 1'[activity_date] &amp;lt;= _ReportDate
                    )
                )
            RETURN
                CALCULATE (
                    SUM ( 'Table 1'[score] ),
                    FILTER (
                        'Table 1',
                        'Table 1'[activity_type] = EARLIER ( [activity_type] )
                            &amp;amp;&amp;amp; 'Table 1'[client_id] = EARLIER ( [client_id] )
                            &amp;amp;&amp;amp; 'Table 1'[activity_date] = _MAXDATE
                    )
                )
    )
RETURN
    AVERAGEX (
        FILTER ( _ADD1, [activity_type] = MAX ( 'Table 1'[activity_type] ) ),
        [Score]
    )&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Number of Clients = 
VAR _ReportDate =
    SELECTEDVALUE ( 'Calendar'[Date] )
VAR _GENERATE =
    GENERATE (
        VALUES ( 'Table 1'[activity_type] ),
        VALUES ( 'Table 1'[client_id] )
    )
VAR _ADD1 =
    ADDCOLUMNS (
        _GENERATE,
        "Score",
            VAR _MAXDATE =
                CALCULATE (
                    MAX ( 'Table 1'[activity_date] ),
                    FILTER (
                        'Table 1',
                        'Table 1'[activity_type] = EARLIER ( [activity_type] )
                            &amp;amp;&amp;amp; 'Table 1'[client_id] = EARLIER ( [client_id] )
                            &amp;amp;&amp;amp; 'Table 1'[activity_date] &amp;lt;= _ReportDate
                    )
                )
            RETURN
                CALCULATE (
                    SUM ( 'Table 1'[score] ),
                    FILTER (
                        'Table 1',
                        'Table 1'[activity_type] = EARLIER ( [activity_type] )
                            &amp;amp;&amp;amp; 'Table 1'[client_id] = EARLIER ( [client_id] )
                            &amp;amp;&amp;amp; 'Table 1'[activity_date] = _MAXDATE
                    )
                )
    )
RETURN
COUNTX(FILTER(_ADD1,[activity_type] = MAX('Table 1'[activity_type]) &amp;amp;&amp;amp; [Score]&amp;lt;&amp;gt;BLANK()),[activity_type])&lt;/LI-CODE&gt;
&lt;P&gt;Result is as below.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 09:50:15 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3439726#M130608</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-09-20T09:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to find the last value for each group in a reporting period and count the average for these rows</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3449206#M131336</link>
      <description>&lt;P&gt;Thank you very much, Rico!&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 08:00:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-find-the-last-value-for-each-group-in-a-reporting-period/m-p/3449206#M131336</guid>
      <dc:creator>marypal</dc:creator>
      <dc:date>2023-09-27T08:00:35Z</dc:date>
    </item>
  </channel>
</rss>

