<?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 reference previous values from the same column where the DAX program/code is being written? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3538616#M135968</link>
    <description>&lt;P&gt;&amp;nbsp;Sample&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2023 12:23:35 GMT</pubDate>
    <dc:creator>Commons94</dc:creator>
    <dc:date>2023-12-05T12:23:35Z</dc:date>
    <item>
      <title>How to reference previous values from the same column where the DAX program/code is being written?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3536735#M135903</link>
      <description>&lt;P&gt;Dear Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem facing me since the past few months. I have multiple conditions (mentioned below) to develop 2 result columns - "Result Date" &amp;amp; "Result Qty". The problem I'm facing is that in some of the conditions, the result has to be the the same result as in the previous rows of the same column where the DAX code is being written. I'm currently performing it in Excel that's why I'm using "XLOOKUP" function.&lt;STRONG&gt; If you take a closer at the XLOOKUP formula, you can see that the result part of the formula references the "Result Date"/"Result Qty" columns which are the columns where the results are printed. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Any suggestions on how this could be done with Power BI would be helpful, as the dataset is large and performing these calculations in Excel doesn't make much sense now.&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Conditions for the 1st results column - "Result Date"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Result Date&lt;/U&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;IF "Previous ID" =""&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then ""&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "SL Type" = "First SL"&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then "Date"&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "SL Type" = "Unconfirmed"&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then XLOOKUP("Previous ID", "Current ID", "Result Date","")&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "SL Type" = "Confirmed" &amp;amp;&amp;amp; "Check"&amp;gt;1&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then "Date"&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "SL Type" = "Confirmed" &amp;amp;&amp;amp; Check =1 &amp;amp;&amp;amp;&lt;UL&gt;&lt;LI&gt;Then "Date"&lt;/LI&gt;&lt;/UL&gt;&lt;UL&gt;&lt;LI&gt;Then XLOOKUP("Previous ID", "Current ID", "Result Date","")&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;IF "Change Required?" = "Change date" || "Change Required" = "Change both"&lt;/LI&gt;&lt;LI&gt;IF "Change Required?" = "Change Qty" || "Change Required" = "no"&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;Else ""&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Conditions for the 2nd results column - "Result Qty"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Result Qty&lt;/U&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;IF "Previous ID" =""&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then ""&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "SL Type" = "First SL"&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then "Qty"&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "SL Type" = "Unconfirmed"&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then XLOOKUP("Previous ID", "Current ID", "Result Qty","")&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "SL Type" = "Confirmed" &amp;amp;&amp;amp; "Check"&amp;gt;1&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then "Qty"&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "SL Type" = "Confirmed" &amp;amp;&amp;amp; Check =1 &amp;amp;&amp;amp;&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;IF "Change Required?" = "Change Qty" &amp;amp;&amp;amp; "Qty decrease?" = "yes"&amp;nbsp;&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then "Qty"&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "Change Required?" = "Change Qty" &amp;amp;&amp;amp; "Qty increase?" = "yes"&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then XLOOKUP("Previous ID", "Current ID", "Result Qty","")&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "Change Required?" = "Change both" &amp;amp;&amp;amp; "Qty decrease?" = "yes"&amp;nbsp;&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then "Qty"&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "Change Required?" = "Change both" &amp;amp;&amp;amp; "Qty increase?" = "yes"&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then XLOOKUP("Previous ID", "Current ID", "Result Qty","")&lt;/LI&gt;&lt;/UL&gt;&lt;LI&gt;IF "Change Required?" = "Change Date" || "Change Required" = "no"&lt;/LI&gt;&lt;UL&gt;&lt;LI&gt;Then XLOOKUP("Previous ID", "Current ID", "Result Qty","")&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;LI&gt;Else ""&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Thu, 16 Nov 2023 09:14:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3536735#M135903</guid>
      <dc:creator>Commons94</dc:creator>
      <dc:date>2023-11-16T09:14:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference previous values from the same column where the DAX program/code is being written?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3538616#M135968</link>
      <description>&lt;P&gt;&amp;nbsp;Sample&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 12:23:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3538616#M135968</guid>
      <dc:creator>Commons94</dc:creator>
      <dc:date>2023-12-05T12:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference previous values from the same column where the DAX program/code is being written?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3541465#M136086</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="584792" data-lia-user-login="Commons94" class="lia-mention lia-mention-user"&gt;Commons94&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I create a sample pbix file(see the attachment), please check if that is what you want.&lt;/P&gt;
&lt;P&gt;1. Create two &lt;STRONG&gt;calculated column&lt;/STRONG&gt;s as below to get the qty and date for the previous ID&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Previous ID Date = 
VAR _pid = 'Table'[Previous ID]
VAR _rdate =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER ( 'Table', 'Table'[Current ID] = _pid )
    )
RETURN
    _rdate&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Previous ID Qty = 
VAR _pid = 'Table'[Previous ID]
VAR _rQty =
    CALCULATE (
        MAX ( 'Table'[Qty] ),
        FILTER ( 'Table', 'Table'[Current ID] = _pid )
    )
RETURN
    _rQty&lt;/LI-CODE&gt;
&lt;P&gt;2. Create two &lt;STRONG&gt;calculated column&lt;/STRONG&gt; as below to get the result data and result qty&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Result Date = 
IF (
    ISBLANK ( [Previous ID] ),
    BLANK (),
    SWITCH (
        TRUE (),
        [SL Type] = "First SL", [Date],
        [SL Type] = "Unconfirmed", [Previous ID Date],
        [SL Type] = "Confirmed"
            &amp;amp;&amp;amp; [Check] &amp;gt; 1, [Date],
        [SL Type] = "Confirmed"
            &amp;amp;&amp;amp; [Check] = 1
            &amp;amp;&amp;amp; [Change Required?] IN { "Change date", "Change both" }, [Date],
        [SL Type] = "Confirmed"
            &amp;amp;&amp;amp; [Check] = 1
            &amp;amp;&amp;amp; [Change Required?] IN { "Change Qty", "no" }, [Previous ID Date]
    )
)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Result Qty = 
IF (
    ISBLANK ( [Previous ID] ),
    BLANK (),
    SWITCH (
        TRUE (),
        [SL Type] = "First SL", [Qty],
        [SL Type] = "Unconfirmed", [Previous ID Qty],
        [SL Type] = "Confirmed"
            &amp;amp;&amp;amp; [Check] &amp;gt; 1, [Qty],
        [SL Type] = "Confirmed"
            &amp;amp;&amp;amp; [Check] = 1
            &amp;amp;&amp;amp; [Change Required?]
            IN { "Change Qty", "Change both" }
                &amp;amp;&amp;amp; 'Table'[Qty decrease?] = "yes", [Qty],
        [SL Type] = "Confirmed"
            &amp;amp;&amp;amp; [Check] = 1
            &amp;amp;&amp;amp; ( ( [Change Required?]
            IN { "Change Qty", "Change both" }
                &amp;amp;&amp;amp; 'Table'[Qty Increase?] = "yes" )
            || 'Table'[Change Required?] IN { "Change Date", "no" } ), [Previous ID Qty]
    )
)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2023 02:57:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3541465#M136086</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-11-20T02:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference previous values from the same column where the DAX program/code is being written?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3542700#M136184</link>
      <description>&lt;P&gt;Hello&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot for your reply and dax-program. It seems to work correctly for the given sample dataset but when I apply it to the complete dataset I don't get the some results where "SL Type" = "Confirmed". Can you please provide your suggestion on how the code can be altered for the following sample dataset? thanks a lot...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 12:23:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3542700#M136184</guid>
      <dc:creator>Commons94</dc:creator>
      <dc:date>2023-12-05T12:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference previous values from the same column where the DAX program/code is being written?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3543528#M136228</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="584792" data-lia-user-login="Commons94" class="lia-mention lia-mention-user"&gt;Commons94&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Could you please provide your expected [Result Date] and [Result Qty] base on above sample data when&amp;nbsp;&lt;SPAN&gt;"SL Type" = "Confirmed"? Thank you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 02:27:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3543528#M136228</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-11-21T02:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference previous values from the same column where the DAX program/code is being written?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3544037#M136257</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks once again for your reply. below you find the expected results, in the "Comment" column you find the reason why these are the expected results. Please take a closer on the ID "5337836_10_037/13", here with the existing formula gives a blank because the lookup value of previous ID is also blank (******/13 has been confirmed 1st time in the sequence that's why).&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 12:24:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3544037#M136257</guid>
      <dc:creator>Commons94</dc:creator>
      <dc:date>2023-12-05T12:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference previous values from the same column where the DAX program/code is being written?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3544199#M136264</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="584792" data-lia-user-login="Commons94" class="lia-mention lia-mention-user"&gt;Commons94&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I updated the sample pbix file, please check if that is what you want. Any comment or problem, please feel free to let me know.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 09:05:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-reference-previous-values-from-the-same-column-where-the/m-p/3544199#M136264</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-11-21T09:05:36Z</dc:date>
    </item>
  </channel>
</rss>

