<?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 How to check values calculated with ADDCOLUMNS in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3138098#M111924</link>
    <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am encountering a calculation issue with Profit and Loss Calculation. (Posted on the community already but hasn't got any reply)&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/DAX-Commands-and-Tips/FIFO-Profit-and-Loss-Calculation-Calculation-Partially-Correct/td-p/3099795" target="_blank"&gt;https://community.powerbi.com/t5/DAX-Commands-and-Tips/FIFO-Profit-and-Loss-Calculation-Calculation-Partially-Correct/td-p/3099795&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To check about the issue, I would like to see the invisible values, "New Value" calculated with ADDCOLUMNS in the formula below.&lt;/P&gt;&lt;P&gt;Could anyone please advise me how I can create a column that shows the calculated "New Value"?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;P&amp;amp;L (FIFO) = 
VAR myClient = 'Order History'[Account Number]
VAR myUniqueOrder = 'Order History'[Index]
VAR myCurrentSell = 'Order History'[Cumulative Sell]
VAR myLastSell = 'Order History'[Previous Cumulative Sell]
VAR mySymbol = 'Order History'[Instrument]
VAR myCumulativeBuy = 'Order History'[Cumulative Buy]
VAR myLastCumulativeBuy = 'Order History'[Previous Cumulative Buy]
VAR FIFOFilterTable =
    FILTER (
        'Order History',
        'Order History'[Account Number] = myClient
            &amp;amp;&amp;amp; 'Order History'[Instrument] = mySymbol
            &amp;amp;&amp;amp; 'Order History'[Index] &amp;lt; myUniqueOrder
            &amp;amp;&amp;amp; 'Order History'[TransType]= "BUY"
            &amp;amp;&amp;amp; ( ( 'Order History'[Cumulative Buy] &amp;gt;= myLastSell
            &amp;amp;&amp;amp; 'Order History'[Cumulative Buy] &amp;lt; myCurrentSell )
            || 'Order History'[Cumulative Buy] &amp;gt;= myCurrentSell
            &amp;amp;&amp;amp; 'Order History'[Previous Cumulative Buy] &amp;lt; myCurrentSell
            || 'Order History'[Previous Cumulative Buy]  &amp;gt; myLastCumulativeBuy
            &amp;amp;&amp;amp; 'Order History'[Cumulative Buy] &amp;lt; myLastCumulativeBuy )
    )
VAR FilteredFIFOTable =
    ADDCOLUMNS (
        FIFOFilterTable,
        "New Value", SWITCH (
            TRUE (),
            'Order History'[Cumulative Buy] &amp;gt; myLastSell
                &amp;amp;&amp;amp; 'Order History'[Previous Cumulative Buy] &amp;lt; myLastSell, 'Order History'[Qty]
                - ( myLastSell - 'Order History'[Previous Cumulative Buy] ),
            'Order History'[Cumulative Buy] &amp;lt; myCurrentSell, 'Order History'[Qty],
            -- ELSE --
            'Order History'[Qty]
                - ( 'Order History'[Cumulative Buy] - myCurrentSell )
        )
    )
VAR Result =
    'Order History'[NetAmountTrade]
        - SUMX ( FilteredFIFOTable, [New Value] *'Order History'[PricePerShare] )
RETURN
    IF ( 'Order History'[TransType] = "SELL", Result )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Peru&lt;/P&gt;</description>
    <pubDate>Fri, 17 Mar 2023 07:26:44 GMT</pubDate>
    <dc:creator>Peru123</dc:creator>
    <dc:date>2023-03-17T07:26:44Z</dc:date>
    <item>
      <title>How to check values calculated with ADDCOLUMNS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3138098#M111924</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am encountering a calculation issue with Profit and Loss Calculation. (Posted on the community already but hasn't got any reply)&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/DAX-Commands-and-Tips/FIFO-Profit-and-Loss-Calculation-Calculation-Partially-Correct/td-p/3099795" target="_blank"&gt;https://community.powerbi.com/t5/DAX-Commands-and-Tips/FIFO-Profit-and-Loss-Calculation-Calculation-Partially-Correct/td-p/3099795&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To check about the issue, I would like to see the invisible values, "New Value" calculated with ADDCOLUMNS in the formula below.&lt;/P&gt;&lt;P&gt;Could anyone please advise me how I can create a column that shows the calculated "New Value"?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;P&amp;amp;L (FIFO) = 
VAR myClient = 'Order History'[Account Number]
VAR myUniqueOrder = 'Order History'[Index]
VAR myCurrentSell = 'Order History'[Cumulative Sell]
VAR myLastSell = 'Order History'[Previous Cumulative Sell]
VAR mySymbol = 'Order History'[Instrument]
VAR myCumulativeBuy = 'Order History'[Cumulative Buy]
VAR myLastCumulativeBuy = 'Order History'[Previous Cumulative Buy]
VAR FIFOFilterTable =
    FILTER (
        'Order History',
        'Order History'[Account Number] = myClient
            &amp;amp;&amp;amp; 'Order History'[Instrument] = mySymbol
            &amp;amp;&amp;amp; 'Order History'[Index] &amp;lt; myUniqueOrder
            &amp;amp;&amp;amp; 'Order History'[TransType]= "BUY"
            &amp;amp;&amp;amp; ( ( 'Order History'[Cumulative Buy] &amp;gt;= myLastSell
            &amp;amp;&amp;amp; 'Order History'[Cumulative Buy] &amp;lt; myCurrentSell )
            || 'Order History'[Cumulative Buy] &amp;gt;= myCurrentSell
            &amp;amp;&amp;amp; 'Order History'[Previous Cumulative Buy] &amp;lt; myCurrentSell
            || 'Order History'[Previous Cumulative Buy]  &amp;gt; myLastCumulativeBuy
            &amp;amp;&amp;amp; 'Order History'[Cumulative Buy] &amp;lt; myLastCumulativeBuy )
    )
VAR FilteredFIFOTable =
    ADDCOLUMNS (
        FIFOFilterTable,
        "New Value", SWITCH (
            TRUE (),
            'Order History'[Cumulative Buy] &amp;gt; myLastSell
                &amp;amp;&amp;amp; 'Order History'[Previous Cumulative Buy] &amp;lt; myLastSell, 'Order History'[Qty]
                - ( myLastSell - 'Order History'[Previous Cumulative Buy] ),
            'Order History'[Cumulative Buy] &amp;lt; myCurrentSell, 'Order History'[Qty],
            -- ELSE --
            'Order History'[Qty]
                - ( 'Order History'[Cumulative Buy] - myCurrentSell )
        )
    )
VAR Result =
    'Order History'[NetAmountTrade]
        - SUMX ( FilteredFIFOTable, [New Value] *'Order History'[PricePerShare] )
RETURN
    IF ( 'Order History'[TransType] = "SELL", Result )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all in advance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Peru&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 07:26:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3138098#M111924</guid>
      <dc:creator>Peru123</dc:creator>
      <dc:date>2023-03-17T07:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to check values calculated with ADDCOLUMNS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3138374#M111943</link>
      <description>&lt;P&gt;You can use DAX Studio to execute queries, so you could show the entire FilteredFIFO table. You would need to use TREATAS to define the filters for a specific row in the Order History table, and you would need to change the definition of each of the variables to use SELECTEDVALUE instead of relying on row context, e.g.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;VAR myClient = SELECTEDVALUE('Order History'[Account Number])&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2023 09:43:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3138374#M111943</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-03-17T09:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to check values calculated with ADDCOLUMNS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3144203#M112400</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your advice!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;According to your advice,&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;&lt;STRONG&gt;Done&lt;/STRONG&gt;: You can use DAX Studio to execute queries, so you could show the entire FilteredFIFO table. &lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;&lt;STRONG&gt;I could not add TREATAS&lt;/STRONG&gt;: You would need to use TREATAS to define the filters for a specific row in the Order History table&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;&lt;STRONG&gt;Done&lt;/STRONG&gt;: you would need to change the definition of each of the variables to use SELECTEDVALUE instead of relying on row context&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could you please advise me where to insert TREATAS?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is the query I currently have. With the below query the table output is empty.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;DEFINE
VAR myClient =
    SELECTEDVALUE ( 'Order History'[Account Number] )
VAR myUniqueOrder =
    SELECTEDVALUE ( 'Order History'[Index] )
VAR myCurrentSell =
    SELECTEDVALUE ( 'Order History'[Cumulative Sell] )
VAR myLastSell =
    SELECTEDVALUE ( 'Order History'[Previous Cumulative Sell] )
VAR mySymbol =
    SELECTEDVALUE ( 'Order History'[Instrument] )
VAR myCumulativeBuy =
    SELECTEDVALUE ( 'Order History'[Cumulative Buy] )
VAR myLastCumulativeBuy =
    SELECTEDVALUE ( 'Order History'[Previous Cumulative Buy] )
VAR FIFOFilterTable =
    FILTER (
        'Order History',
        'Order History'[Account Number] = myClient
            &amp;amp;&amp;amp; 'Order History'[Instrument] = mySymbol
            &amp;amp;&amp;amp; 'Order History'[Index] &amp;lt; myUniqueOrder
            &amp;amp;&amp;amp; 'Order History'[TransType] = "BUY"
            &amp;amp;&amp;amp; ( ( 'Order History'[Cumulative Buy] &amp;gt;= myLastSell
            &amp;amp;&amp;amp; 'Order History'[Cumulative Buy] &amp;lt; myCurrentSell )
            || 'Order History'[Cumulative Buy] &amp;gt;= myCurrentSell
            &amp;amp;&amp;amp; 'Order History'[Previous Cumulative Buy] &amp;lt; myCurrentSell
            || 'Order History'[Previous Cumulative Buy] &amp;gt; myLastCumulativeBuy
            &amp;amp;&amp;amp; 'Order History'[Cumulative Buy] &amp;lt; myLastCumulativeBuy )
    )

EVALUATE
    ADDCOLUMNS (
        FIFOFilterTable,
        "New Value",
            SWITCH (
                TRUE (),
                'Order History'[Cumulative Buy] &amp;gt; myLastSell
                    &amp;amp;&amp;amp; 'Order History'[Previous Cumulative Buy] &amp;lt; myLastSell,
                    'Order History'[Qty] - ( myLastSell - 'Order History'[Previous Cumulative Buy] ),
                'Order History'[Cumulative Buy] &amp;lt; myCurrentSell, 'Order History'[Qty],
                -- ELSE --
                'Order History'[Qty] - ( 'Order History'[Cumulative Buy] - myCurrentSell )
            )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 09:13:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3144203#M112400</guid>
      <dc:creator>Peru123</dc:creator>
      <dc:date>2023-03-21T09:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to check values calculated with ADDCOLUMNS</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3144244#M112401</link>
      <description>&lt;P&gt;You need to tell the engine which row of Order History you want to run the calculation for. The below code assumes that 'Order History'[Index] uniquely identifies a row in the table. If it doesn't then you will need to add additional columns and values to the TREATAS such that they identify a unique row.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;DEFINE
    VAR OrderFilter =
        TREATAS ( { 1 }, 'Order History'[Index] )

EVALUATE
CALCULATETABLE (
    VAR myClient =
        SELECTEDVALUE ( 'Order History'[Account Number] )
    VAR myUniqueOrder =
        SELECTEDVALUE ( 'Order History'[Index] )
    VAR myCurrentSell =
        SELECTEDVALUE ( 'Order History'[Cumulative Sell] )
    VAR myLastSell =
        SELECTEDVALUE ( 'Order History'[Previous Cumulative Sell] )
    VAR mySymbol =
        SELECTEDVALUE ( 'Order History'[Instrument] )
    VAR myCumulativeBuy =
        SELECTEDVALUE ( 'Order History'[Cumulative Buy] )
    VAR myLastCumulativeBuy =
        SELECTEDVALUE ( 'Order History'[Previous Cumulative Buy] )
    VAR FIFOFilterTable =
        FILTER (
            'Order History',
            'Order History'[Account Number] = myClient
                &amp;amp;&amp;amp; 'Order History'[Instrument] = mySymbol
                &amp;amp;&amp;amp; 'Order History'[Index] &amp;lt; myUniqueOrder
                &amp;amp;&amp;amp; 'Order History'[TransType] = "BUY"
                &amp;amp;&amp;amp; ( ( 'Order History'[Cumulative Buy] &amp;gt;= myLastSell
                &amp;amp;&amp;amp; 'Order History'[Cumulative Buy] &amp;lt; myCurrentSell )
                || 'Order History'[Cumulative Buy] &amp;gt;= myCurrentSell
                &amp;amp;&amp;amp; 'Order History'[Previous Cumulative Buy] &amp;lt; myCurrentSell
                || 'Order History'[Previous Cumulative Buy] &amp;gt; myLastCumulativeBuy
                &amp;amp;&amp;amp; 'Order History'[Cumulative Buy] &amp;lt; myLastCumulativeBuy )
        )
    RETURN
        ADDCOLUMNS (
            FIFOFilterTable,
            "New Value",
                SWITCH (
                    TRUE (),
                    'Order History'[Cumulative Buy] &amp;gt; myLastSell
                        &amp;amp;&amp;amp; 'Order History'[Previous Cumulative Buy] &amp;lt; myLastSell,
                        'Order History'[Qty] - ( myLastSell - 'Order History'[Previous Cumulative Buy] ),
                    'Order History'[Cumulative Buy] &amp;lt; myCurrentSell, 'Order History'[Qty],
                    -- ELSE --
                    'Order History'[Qty] - ( 'Order History'[Cumulative Buy] - myCurrentSell )
                )
        ),
    OrderFilter
)
&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 21 Mar 2023 09:37:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-check-values-calculated-with-ADDCOLUMNS/m-p/3144244#M112401</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-03-21T09:37:24Z</dc:date>
    </item>
  </channel>
</rss>

