<?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: Dax Measure in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4711316#M180434</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1277713" data-lia-user-login="LoganFFS" class="lia-mention lia-mention-user"&gt;LoganFFS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="1055" data-end="1117"&gt;1: Create an Index column in Power Query or using DAX&lt;/H3&gt;
&lt;P data-start="1119" data-end="1247"&gt;If you can use Power Query, add an &lt;STRONG data-start="1154" data-end="1170"&gt;Index Column&lt;/STRONG&gt; after sorting the data by Date and Name or Symbol. If you must do it in DAX:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ActionIndex = 
RANKX(
    FILTER(
        'Table', 
        'Table'[Name] = EARLIER('Table'[Name])
    ),
    'Table'[Date],
    ,
    ASC,
    DENSE
)
&lt;/LI-CODE&gt;
&lt;P&gt;This gives a sequence number per name sorted by date.&lt;/P&gt;
&lt;H3 data-start="1468" data-end="1519"&gt;2: Find the next buy index after each sell&lt;/H3&gt;
&lt;P data-start="1521" data-end="1589"&gt;Create a calculated column to find the next buy index for each sell:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;NextBuyIndex = 
CALCULATE(
    MIN('Table'[ActionIndex]),
    FILTER(
        'Table',
        'Table'[Name] = EARLIER('Table'[Name]) &amp;amp;&amp;amp;
        'Table'[Action] = "buy" &amp;amp;&amp;amp;
        'Table'[ActionIndex] &amp;gt; EARLIER('Table'[ActionIndex])
    )
)
&lt;/LI-CODE&gt;
&lt;P&gt;This finds the earliest buy after the sell for the same Name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="1907" data-end="1954"&gt;3: Retrieve the price of that next buy&lt;/H3&gt;
&lt;P data-start="1956" data-end="1980"&gt;Add a calculated column:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;PriceOfNextBuy = 
LOOKUPVALUE(
    'Table'[Price],
    'Table'[Name], 'Table'[Name],
    'Table'[ActionIndex], 'Table'[NextBuyIndex]
)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="2129" data-end="2184"&gt;4: Calculate average price of these first buys&lt;/H3&gt;
&lt;P data-start="2186" data-end="2258"&gt;Finally, create a measure to average all such next buy prices for sells:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;AvgPriceFirstBuyAfterSell = 
AVERAGEX(
    FILTER('Table', 'Table'[Action] = "sell" &amp;amp;&amp;amp; NOT(ISBLANK('Table'[PriceOfNextBuy]))),
    'Table'[PriceOfNextBuy]
)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="2434" data-end="2720"&gt;By indexing actions per entity ordered by date, then for each sell finding the next buy, retrieving its price, and averaging those prices, you can calculate the average price of the first buy after a sell, even if multiple actions occur on the same day with no timestamp.&lt;/P&gt;
&lt;P data-start="2722" data-end="3008" data-is-last-node="" data-is-only-node=""&gt;This solution requires creating calculated columns and measures in DAX, and assumes you can establish a consistent ordering of actions per entity by date (and possibly by some stable secondary sorting if needed). This is the best way to handle sequencing without timestamps in Power BI.&lt;/P&gt;</description>
    <pubDate>Thu, 29 May 2025 05:07:45 GMT</pubDate>
    <dc:creator>Poojara_D12</dc:creator>
    <dc:date>2025-05-29T05:07:45Z</dc:date>
    <item>
      <title>Dax Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4709624#M180367</link>
      <description>&lt;P&gt;Hi there, I am hoping someone has a solution to this problem. I have a data set in my dashboard with "date", "name", "symbol", "action" and "price". I am trying to figure out how to calculate the average price of the first "buy" after a "sell"(which are both in the action column). I have run into trouble because there are multiple buys and sells on the same "date", and no timestamp to differentiate. Ideally I am able to calculate the average first buy after a sell, whether it needs to be done with a measure and a caculated column or just a measure. Anyways any help is appreciated. Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 May 2025 23:44:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4709624#M180367</guid>
      <dc:creator>LoganFFS</dc:creator>
      <dc:date>2025-05-27T23:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4709778#M180374</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1277713" target="_self"&gt;&lt;SPAN class=""&gt;LoganFFS&lt;/SPAN&gt;&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please find the attached pbix file with a solution for you problem description.&lt;BR /&gt;&lt;A href="https://cloudbiexpert-my.sharepoint.com/:u:/p/maruthi/EQx1MYWtpCVBtPA94jYJETABvdVuWv4MwvUuEYKPxz4hmA?e=ui1ekE" target="_blank" rel="noopener"&gt;Dax Measure.pbix&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if you have further questions.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;If this reply helped solve your problem, please consider clicking "Accept as Solution" so others can benefit too.&amp;nbsp;And if you found it useful, a quick "Kudos" is always appreciated, thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best Regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maruthi&amp;nbsp;&lt;/P&gt;&lt;P&gt;LinkedIn -&amp;nbsp;&lt;A href="http://www.linkedin.com/in/maruthi-siva-prasad/" target="_blank" rel="nofollow noopener noreferrer"&gt;http://www.linkedin.com/in/maruthi-siva-prasad/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X&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;&lt;A href="https://x.com/maruthisp" target="_blank" rel="nofollow noopener noreferrer"&gt;Maruthi Siva Prasad - (@MaruthiSP) / X&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 04:14:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4709778#M180374</guid>
      <dc:creator>maruthisp</dc:creator>
      <dc:date>2025-05-28T04:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4710253#M180392</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1277713" data-lia-user-login="LoganFFS" class="lia-mention lia-mention-user"&gt;LoganFFS&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you for reaching out to us on the Microsoft Fabric Community Forum.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please follow below steps.&lt;/P&gt;
&lt;P&gt;Step 1: Add an Index Column, Since there’s no timestamp, we need an index column that gives us the row order. Do this in &lt;BR /&gt;Power Query:&lt;/P&gt;
&lt;P&gt;Sort by Date, Name, Symbol. Add an Index column starting from 1 (call it RowIndex).&lt;/P&gt;
&lt;P&gt;Step 2:DAX Measure to Get First Buy After Each Sell&lt;/P&gt;
&lt;P&gt;Create a measure with below DAX&lt;/P&gt;
&lt;P&gt;AverageFirstBuyAfterSell =&lt;BR /&gt;VAR SellTable =&lt;BR /&gt;FILTER (&lt;BR /&gt;ALL ( Table ),&lt;BR /&gt;Table[Action] = "Sell"&lt;BR /&gt;)&lt;BR /&gt;VAR FirstBuyAfterSellTable =&lt;BR /&gt;ADDCOLUMNS (&lt;BR /&gt;SellTable,&lt;BR /&gt;"FirstBuyPrice",&lt;BR /&gt;CALCULATE (&lt;BR /&gt;MINX (&lt;BR /&gt;TOPN (&lt;BR /&gt;1,&lt;BR /&gt;FILTER (&lt;BR /&gt;ALL ( Table ),&lt;BR /&gt;Table[RowIndex] &amp;gt; EARLIER ( Table[RowIndex] )&lt;BR /&gt;&amp;amp;&amp;amp; Table[Action] = "Buy"&lt;BR /&gt;),&lt;BR /&gt;Table[RowIndex], ASC&lt;BR /&gt;),&lt;BR /&gt;Table[Price]&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;AVERAGEX (&lt;BR /&gt;FirstBuyAfterSellTable,&lt;BR /&gt;[FirstBuyPrice]&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 3 : Drag all the fields in table visual.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer sample data and output snaps and PBIX file.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;If my response has resolved your query, please mark it as the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;"Accepted Solution"&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;to assist others. Additionally, a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;"Kudos"&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;would be appreciated if you found my response helpful.&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 10:05:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4710253#M180392</guid>
      <dc:creator>v-dineshya</dc:creator>
      <dc:date>2025-05-28T10:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4711099#M180422</link>
      <description>&lt;P&gt;Hi there, I tried it today. The index column I added in just fine, but the measure gave me trouble. When I entered the measure, I entered it into a number visual hoping to display the average instead of at the bottom of the dataset. I attached a photo of what i hope to achieve. Whether it needs to be done in one measure or two calculated columns im not sure. I only want to have a value in the new column where there is a buy directly after a sell so that I can average that column easier. This should hopefully clear up what im trying to achieve. Thanks in advance!&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2025 01:32:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4711099#M180422</guid>
      <dc:creator>LoganFFS</dc:creator>
      <dc:date>2025-05-29T01:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4711316#M180434</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1277713" data-lia-user-login="LoganFFS" class="lia-mention lia-mention-user"&gt;LoganFFS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="1055" data-end="1117"&gt;1: Create an Index column in Power Query or using DAX&lt;/H3&gt;
&lt;P data-start="1119" data-end="1247"&gt;If you can use Power Query, add an &lt;STRONG data-start="1154" data-end="1170"&gt;Index Column&lt;/STRONG&gt; after sorting the data by Date and Name or Symbol. If you must do it in DAX:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ActionIndex = 
RANKX(
    FILTER(
        'Table', 
        'Table'[Name] = EARLIER('Table'[Name])
    ),
    'Table'[Date],
    ,
    ASC,
    DENSE
)
&lt;/LI-CODE&gt;
&lt;P&gt;This gives a sequence number per name sorted by date.&lt;/P&gt;
&lt;H3 data-start="1468" data-end="1519"&gt;2: Find the next buy index after each sell&lt;/H3&gt;
&lt;P data-start="1521" data-end="1589"&gt;Create a calculated column to find the next buy index for each sell:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;NextBuyIndex = 
CALCULATE(
    MIN('Table'[ActionIndex]),
    FILTER(
        'Table',
        'Table'[Name] = EARLIER('Table'[Name]) &amp;amp;&amp;amp;
        'Table'[Action] = "buy" &amp;amp;&amp;amp;
        'Table'[ActionIndex] &amp;gt; EARLIER('Table'[ActionIndex])
    )
)
&lt;/LI-CODE&gt;
&lt;P&gt;This finds the earliest buy after the sell for the same Name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="1907" data-end="1954"&gt;3: Retrieve the price of that next buy&lt;/H3&gt;
&lt;P data-start="1956" data-end="1980"&gt;Add a calculated column:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;PriceOfNextBuy = 
LOOKUPVALUE(
    'Table'[Price],
    'Table'[Name], 'Table'[Name],
    'Table'[ActionIndex], 'Table'[NextBuyIndex]
)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 data-start="2129" data-end="2184"&gt;4: Calculate average price of these first buys&lt;/H3&gt;
&lt;P data-start="2186" data-end="2258"&gt;Finally, create a measure to average all such next buy prices for sells:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;AvgPriceFirstBuyAfterSell = 
AVERAGEX(
    FILTER('Table', 'Table'[Action] = "sell" &amp;amp;&amp;amp; NOT(ISBLANK('Table'[PriceOfNextBuy]))),
    'Table'[PriceOfNextBuy]
)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P data-start="2434" data-end="2720"&gt;By indexing actions per entity ordered by date, then for each sell finding the next buy, retrieving its price, and averaging those prices, you can calculate the average price of the first buy after a sell, even if multiple actions occur on the same day with no timestamp.&lt;/P&gt;
&lt;P data-start="2722" data-end="3008" data-is-last-node="" data-is-only-node=""&gt;This solution requires creating calculated columns and measures in DAX, and assumes you can establish a consistent ordering of actions per entity by date (and possibly by some stable secondary sorting if needed). This is the best way to handle sequencing without timestamps in Power BI.&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2025 05:07:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4711316#M180434</guid>
      <dc:creator>Poojara_D12</dc:creator>
      <dc:date>2025-05-29T05:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4716281#M180646</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="1277713" data-lia-user-login="LoganFFS" class="lia-mention lia-mention-user"&gt;LoganFFS&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jun 2025 07:05:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4716281#M180646</guid>
      <dc:creator>v-dineshya</dc:creator>
      <dc:date>2025-06-02T07:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4721295#M180822</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1277713" target="_blank"&gt;@LoganFFS&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 10:57:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4721295#M180822</guid>
      <dc:creator>v-dineshya</dc:creator>
      <dc:date>2025-06-05T10:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Dax Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4724792#M180972</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1277713" target="_blank" rel="noopener"&gt;@LoganFFS&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 03:55:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-Measure/m-p/4724792#M180972</guid>
      <dc:creator>v-dineshya</dc:creator>
      <dc:date>2025-06-09T03:55:55Z</dc:date>
    </item>
  </channel>
</rss>

