<?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: Calculate last entry per Order in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-last-entry-per-Order/m-p/2807010#M88621</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92006" data-lia-user-login="joshua1990" class="lia-mention lia-mention-user"&gt;joshua1990&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please try&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Sum of Last Version =
SUMX (
    VALUES ( 'Table'[Order Nr] ),
    CALCULATE ( MAXX ( TOPN ( 1, 'Table', 'Table'[Version] ), 'Table'[Value] ) )
)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 29 Sep 2022 17:30:43 GMT</pubDate>
    <dc:creator>tamerj1</dc:creator>
    <dc:date>2022-09-29T17:30:43Z</dc:date>
    <item>
      <title>Calculate last entry per Order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-last-entry-per-Order/m-p/2806617#M88576</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;ich have a sales table that shows multiple rows for each order since there are changes. Each change is recorded with a new version number:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;Order Nr&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Value&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;Version&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;5&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;4&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;2&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;9&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%"&gt;3&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;7&lt;/TD&gt;
&lt;TD width="33.333333333333336%"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I would like to calculate the sum [Value] for each order with latest version.&lt;/P&gt;
&lt;P&gt;How would you do that? Using MAXX und Sum?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 13:56:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-last-entry-per-Order/m-p/2806617#M88576</guid>
      <dc:creator>joshua1990</dc:creator>
      <dc:date>2022-09-29T13:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate last entry per Order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-last-entry-per-Order/m-p/2806642#M88578</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[Total Value] =
// Be careful not to filter the Sales table
// by Value or Version because the measure
// here is sensitive to filters (which is
// OK and that's how it should be). For instance,
// if you filter by Order Nr and Version, then
// the version filtered by will be effective,
// not necessarily the latest one. If you don't
// filter by Version, you'll get what you want - 
// the latest version. Same for Value.
var OrdersWithLatestVersions = 
    generate(
        values( Sales[Order Nr] ),
        row( 
            "@LatestVersion", 
            calculate( max( Sales[Version] ) )
        )
    )
var Output =
    calculate(
        sum( Sales[Value] ),
        treatas(
            OrdersWithLatestVersions,
            Sales[Order Nr],
            Sales[Version]
        )
    )
return
    Output&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a different method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[Total Value] =
sumx(
    generate(
        selectcolumns(
            values( Sales[Order Nr] ),
            "@OrderNumber", Sales[Order Nr]
        ),
        calculatetable(
            topn(1,
                Sales,
                Sales[Version],
                DESC
            )
        )
    ),
    Sales[Value]
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 14:17:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-last-entry-per-Order/m-p/2806642#M88578</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-09-29T14:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate last entry per Order</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-last-entry-per-Order/m-p/2807010#M88621</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92006" data-lia-user-login="joshua1990" class="lia-mention lia-mention-user"&gt;joshua1990&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please try&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;Sum of Last Version =
SUMX (
    VALUES ( 'Table'[Order Nr] ),
    CALCULATE ( MAXX ( TOPN ( 1, 'Table', 'Table'[Version] ), 'Table'[Value] ) )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 29 Sep 2022 17:30:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-last-entry-per-Order/m-p/2807010#M88621</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-09-29T17:30:43Z</dc:date>
    </item>
  </channel>
</rss>

