<?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 Want to convert a sql function into dax for a direct query in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Want-to-convert-a-sql-function-into-dax-for-a-direct-query/m-p/3747323#M146160</link>
    <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to convert the below sql query column into dax for a direct query option. Can you please help how to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;&lt;SPAN&gt;SUM(BIDS) OVER (PARTITION BY&amp;nbsp;DRID,INTRL_DATE,PERD_ID ORDER BY BND ASC) as CUM_BIDS&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- GREATEST(0,BID_AVAIL + LEAST(0,INIAL_MW - CUM_BIDS&amp;nbsp;))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Laiq&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Mar 2024 00:36:25 GMT</pubDate>
    <dc:creator>Laiq_Rahman</dc:creator>
    <dc:date>2024-03-07T00:36:25Z</dc:date>
    <item>
      <title>Want to convert a sql function into dax for a direct query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Want-to-convert-a-sql-function-into-dax-for-a-direct-query/m-p/3747323#M146160</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to convert the below sql query column into dax for a direct query option. Can you please help how to do that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-&amp;nbsp;&lt;SPAN&gt;SUM(BIDS) OVER (PARTITION BY&amp;nbsp;DRID,INTRL_DATE,PERD_ID ORDER BY BND ASC) as CUM_BIDS&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- GREATEST(0,BID_AVAIL + LEAST(0,INIAL_MW - CUM_BIDS&amp;nbsp;))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Laiq&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 00:36:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Want-to-convert-a-sql-function-into-dax-for-a-direct-query/m-p/3747323#M146160</guid>
      <dc:creator>Laiq_Rahman</dc:creator>
      <dc:date>2024-03-07T00:36:25Z</dc:date>
    </item>
    <item>
      <title>Re: Want to convert a sql function into dax for a direct query</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Want-to-convert-a-sql-function-into-dax-for-a-direct-query/m-p/3747735#M146170</link>
      <description>&lt;P&gt;To translate the provided SQL function into DAX for a direct query option, you need to understand the logic of the SQL function and then find the corresponding functions and operations in DAX.&lt;/P&gt;&lt;P&gt;Let's break down the SQL functions:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;SUM(BIDS) OVER (PARTITION BY DRID,INTRL_DATE,PERD_ID ORDER BY BND ASC) as CUM_BIDS: This is a window function in SQL that calculates the cumulative sum of the column BIDS partitioned by DRID, INTRL_DATE, and PERD_ID, ordered by BND in ascending order.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;GREATEST(0,BID_AVAIL + LEAST(0,INIAL_MW - CUM_BIDS )): This function calculates the maximum value between 0 and the sum of BID_AVAIL and the minimum value between 0 and the difference between INIAL_MW and CUM_BIDS.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Now, translating this into DAX, assuming you're working in Power BI or another DAX-supported environment, you can follow these steps:&lt;/P&gt;&lt;P&gt;For the first part (SUM(BIDS) OVER...), you can achieve this using DAX's SUMX and FILTER functions to calculate the cumulative sum within a certain context.&lt;/P&gt;&lt;P&gt;For the second part (GREATEST(0,BID_AVAIL + LEAST(0,INIAL_MW - CUM_BIDS))), you can use DAX functions such as MAXX and MINX to find the maximum and minimum values.&lt;/P&gt;&lt;P&gt;Here's how you can write the DAX expression:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CUM_BIDS =&lt;BR /&gt;VAR CumulativeBids =&lt;BR /&gt;CALCULATE(&lt;BR /&gt;SUM('Table'[BIDS]),&lt;BR /&gt;FILTER(&lt;BR /&gt;ALL('Table'),&lt;BR /&gt;'Table'[DRID] = EARLIER('Table'[DRID]) &amp;amp;&amp;amp;&lt;BR /&gt;'Table'[INTRL_DATE] = EARLIER('Table'[INTRL_DATE]) &amp;amp;&amp;amp;&lt;BR /&gt;'Table'[PERD_ID] = EARLIER('Table'[PERD_ID]) &amp;amp;&amp;amp;&lt;BR /&gt;'Table'[BND] &amp;lt;= EARLIER('Table'[BND])&lt;BR /&gt;)&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;CumulativeBids&lt;/P&gt;&lt;P&gt;Max_Bid =&lt;BR /&gt;MAXX('Table', 0, 'Table'[BID_AVAIL] + MINX('Table', 0, 'Table'[INIAL_MW] - 'Table'[CUM_BIDS]))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this DAX expression:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;CUM_BIDS: It calculates the cumulative sum of the BIDS column partitioned by DRID, INTRL_DATE, and PERD_ID.&lt;/LI&gt;&lt;LI&gt;Max_Bid: It calculates the maximum value between 0 and the sum of BID_AVAIL and the minimum value between 0 and the difference between INIAL_MW and CUM_BIDS.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Please replace 'Table' with the appropriate table name in your data model. This DAX expression assumes a table structure similar to your SQL query. Adjust column names and table names as per your data model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2024 05:11:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Want-to-convert-a-sql-function-into-dax-for-a-direct-query/m-p/3747735#M146170</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-03-07T05:11:23Z</dc:date>
    </item>
  </channel>
</rss>

