<?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: Count Total Number of Assets Purchased but not Sold in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152353#M112962</link>
    <description>&lt;P&gt;You could try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Num unsold items =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR PurchasedItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Asset Reference] ),
        'Table'[Transaction date] &amp;lt;= ReferenceDate,
        'Table'[Transaction type] = "Purchase"
    )
VAR SoldItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Asset Reference] ),
        'Table'[Transaction date] &amp;lt;= ReferenceDate,
        'Table'[Transaction type] = "Sale"
    )
VAR UnsoldItems =
    EXCEPT ( PurchasedItems, SoldItems )
RETURN
    COUNTROWS ( UnsoldItems )
&lt;/LI-CODE&gt;
&lt;P&gt;This should work if an asset can only be bought and sold once. If an asset can be purchased then sold and then repurchased then different code would be needed.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Mar 2023 11:30:33 GMT</pubDate>
    <dc:creator>johnt75</dc:creator>
    <dc:date>2023-03-24T11:30:33Z</dc:date>
    <item>
      <title>Count Total Number of Assets Purchased but not Sold</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152313#M112957</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a table in my data model like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Asset Reference&amp;nbsp;&amp;nbs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TD&gt;Purchase&lt;/TD&gt;&lt;TD&gt;15-Dec-16&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AAA002&lt;/TD&gt;&lt;TD&gt;Sale&lt;/TD&gt;&lt;TD&gt;30-Jul-21&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;AAA001&lt;/TD&gt;&lt;TD&gt;Purchase&lt;/TD&gt;&lt;TD&gt;15-Dec-16&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I would like to get a grand total in a card visual of assets that have been purchased but not sold, as per [as of date] which is a date picker the user selects in the report.&lt;/P&gt;&lt;P&gt;So, for example, if the [as of date] = 31/12/2022, from the above there should be a total of 6 assets currently purchased but not sold.&lt;/P&gt;&lt;P&gt;I'm thinking this might need the sum of a filtered count that searches for 'Purchase' or 'Sale' for each asset. But there might be a more efficient way of doing this. Any help appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 11:09:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152313#M112957</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-03-24T11:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Count Total Number of Assets Purchased but not Sold</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152353#M112962</link>
      <description>&lt;P&gt;You could try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Num unsold items =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR PurchasedItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Asset Reference] ),
        'Table'[Transaction date] &amp;lt;= ReferenceDate,
        'Table'[Transaction type] = "Purchase"
    )
VAR SoldItems =
    CALCULATETABLE (
        VALUES ( 'Table'[Asset Reference] ),
        'Table'[Transaction date] &amp;lt;= ReferenceDate,
        'Table'[Transaction type] = "Sale"
    )
VAR UnsoldItems =
    EXCEPT ( PurchasedItems, SoldItems )
RETURN
    COUNTROWS ( UnsoldItems )
&lt;/LI-CODE&gt;
&lt;P&gt;This should work if an asset can only be bought and sold once. If an asset can be purchased then sold and then repurchased then different code would be needed.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 11:30:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152353#M112962</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-03-24T11:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count Total Number of Assets Purchased but not Sold</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152386#M112964</link>
      <description>&lt;P&gt;Thank you&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;You are right - your solution does work for 99% of assets, but there is the possibilty that an asset could be purchased, sold and then purchased again, and I think there is one case where this is so. Even if not, there could potentially be a case of this in the future.&lt;BR /&gt;So I was thinking of some form of count for each asset of 'purchase' transactions, and a count of 'sale' transactions and if purchase is greater than sale then it can be counted as +1.&lt;BR /&gt;I am not sure the most efficient way to express it in the DAX though or if that is the best logical way of achieving the goal?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 11:42:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152386#M112964</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-03-24T11:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count Total Number of Assets Purchased but not Sold</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152401#M112965</link>
      <description>&lt;P&gt;Yes, that should work. Try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Num unsold items =
VAR ReferenceDate =
    MAX ( 'Date'[Date] )
VAR SummaryTable =
    ADDCOLUMNS (
        VALUES ( 'Table'[Asset Reference] ),
        "@purchased",
            CALCULATE (
                COUNTROWS ( 'Table' ),
                'Table'[Transaction Date] &amp;lt;= ReferenceDate,
                'Table'[Transaction type] = "Purchase"
            ),
        "@sold",
            CALCULATE (
                COUNTROWS ( 'Table' ),
                'Table'[Transaction Date] &amp;lt;= ReferenceDate,
                'Table'[Transaction type] = "Sale"
            )
    )
RETURN
    COUNTROWS ( FILTER ( SummaryTable, [@purchased] &amp;gt; [@sold] ) )
&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 11:48:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152401#M112965</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-03-24T11:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Count Total Number of Assets Purchased but not Sold</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152504#M112974</link>
      <description>&lt;P&gt;It works perfectly. Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 12:34:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-Total-Number-of-Assets-Purchased-but-not-Sold/m-p/3152504#M112974</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-03-24T12:34:47Z</dc:date>
    </item>
  </channel>
</rss>

