<?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: Output only the latest value for X and the previous value in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-only-the-latest-value-for-X-and-the-previous-value/m-p/757654#M3085</link>
    <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Please see the below M code, this should give you the desired result.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcjy0QAGMlHSUjIDYEEQbGFoaGBoYKsXqRCtFISkwBmJzhAIjsAJkEwxRFRiDFTihKTBCKDDBUGAEtQaqwBSswBnNBFOEAjOsbjBDKDBXio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Seller = _t, #"Product ID" = _t, Price = _t, DateOffered = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Seller", type text}, {"Product ID", Int64.Type}, {"Price", Int64.Type}, {"DateOffered", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product ID"}, {{"Count", 
        each
            Table.AddIndexColumn( 
                Table.FirstN( 
                    Table.SelectColumns( 
                        Table.Sort( _, {{"DateOffered", Order.Descending}} ), {"Seller", "Price"} ), 2 
                ),
                "Index", 0, 1
            ), 
        type table [Seller=text, Price=number, Index=text]}}
    ),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Seller", "Price", "Index"}, {"Seller", "Price", "Index"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Expanded Count", {"Product ID", "Index"}, "Attribute", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Columns",{{"Index", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1","0","Current",Replacer.ReplaceText,{"Index"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","1","Previous",Replacer.ReplaceText,{"Index"}),
    #"Merged Columns" = Table.CombineColumns(#"Replaced Value1",{"Index", "Attribute"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Pivoted Column",{{"Product ID", Int64.Type}, {"Current Seller", type text}, {"Current Price", Int64.Type}, {"Previous Seller", type text}, {"Previous Price", Int64.Type}})
in
    #"Changed Type2"&lt;/PRE&gt;&lt;P&gt;Input table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;Best Regards,&lt;BR /&gt;Mariusz&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;I&gt;Accepting it as the solution&lt;/I&gt;&lt;/STRONG&gt;.&lt;BR /&gt;&lt;BR /&gt;Please feel free to connect with me.&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/mariusz-repczynski-065a7362/" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;IMG src="https://ip1.i.lithium.com/1232d707bb27fc4afa3b81cd0702c478b6f7aced/68747470733a2f2f7374617469632e6c6963646e2e636f6d2f736364732f636f6d6d6f6e2f752f696d616765732f6c6f676f732f6c696e6b6564696e2f6c6f676f5f6c696e6b6564696e5f39337832315f76322e706e67" border="0" alt="Mariusz Repczynski" /&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Aug 2019 10:24:41 GMT</pubDate>
    <dc:creator>Mariusz</dc:creator>
    <dc:date>2019-08-05T10:24:41Z</dc:date>
    <item>
      <title>Output only the latest value for X and the previous value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-only-the-latest-value-for-X-and-the-previous-value/m-p/757599#M3082</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table that looks something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Seller || Product ID || Price || DateOffered&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20190101&lt;/P&gt;&lt;P&gt;Z&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20190102&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20190103&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20190104&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20190105&lt;/P&gt;&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20190106&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 20190107&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only want to get the data where seller A is the current seller,&lt;/P&gt;&lt;P&gt;whos is the previous seller and what is the previous price.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;Product&amp;nbsp; || Current Seller ||&amp;nbsp; Current Price || Previous Seller ||&amp;nbsp; Previous Price ||&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&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;C&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; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 09:31:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-only-the-latest-value-for-X-and-the-previous-value/m-p/757599#M3082</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-05T09:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Output only the latest value for X and the previous value</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-only-the-latest-value-for-X-and-the-previous-value/m-p/757654#M3085</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Please see the below M code, this should give you the desired result.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcjy0QAGMlHSUjIDYEEQbGFoaGBoYKsXqRCtFISkwBmJzhAIjsAJkEwxRFRiDFTihKTBCKDDBUGAEtQaqwBSswBnNBFOEAjOsbjBDKDBXio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Seller = _t, #"Product ID" = _t, Price = _t, DateOffered = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Seller", type text}, {"Product ID", Int64.Type}, {"Price", Int64.Type}, {"DateOffered", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Product ID"}, {{"Count", 
        each
            Table.AddIndexColumn( 
                Table.FirstN( 
                    Table.SelectColumns( 
                        Table.Sort( _, {{"DateOffered", Order.Descending}} ), {"Seller", "Price"} ), 2 
                ),
                "Index", 0, 1
            ), 
        type table [Seller=text, Price=number, Index=text]}}
    ),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Seller", "Price", "Index"}, {"Seller", "Price", "Index"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Expanded Count", {"Product ID", "Index"}, "Attribute", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Unpivoted Columns",{{"Index", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type1","0","Current",Replacer.ReplaceText,{"Index"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","1","Previous",Replacer.ReplaceText,{"Index"}),
    #"Merged Columns" = Table.CombineColumns(#"Replaced Value1",{"Index", "Attribute"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Pivoted Column",{{"Product ID", Int64.Type}, {"Current Seller", type text}, {"Current Price", Int64.Type}, {"Previous Seller", type text}, {"Previous Price", Int64.Type}})
in
    #"Changed Type2"&lt;/PRE&gt;&lt;P&gt;Input table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output table.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;Best Regards,&lt;BR /&gt;Mariusz&lt;BR /&gt;&lt;BR /&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;I&gt;Accepting it as the solution&lt;/I&gt;&lt;/STRONG&gt;.&lt;BR /&gt;&lt;BR /&gt;Please feel free to connect with me.&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/mariusz-repczynski-065a7362/" rel="nofollow noopener noreferrer" target="_blank"&gt;&lt;IMG src="https://ip1.i.lithium.com/1232d707bb27fc4afa3b81cd0702c478b6f7aced/68747470733a2f2f7374617469632e6c6963646e2e636f6d2f736364732f636f6d6d6f6e2f752f696d616765732f6c6f676f732f6c696e6b6564696e2f6c6f676f5f6c696e6b6564696e5f39337832315f76322e706e67" border="0" alt="Mariusz Repczynski" /&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 10:24:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Output-only-the-latest-value-for-X-and-the-previous-value/m-p/757654#M3085</guid>
      <dc:creator>Mariusz</dc:creator>
      <dc:date>2019-08-05T10:24:41Z</dc:date>
    </item>
  </channel>
</rss>

