<?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 Command- Need Help in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Command-Need-Help/m-p/4321158#M171554</link>
    <description>&lt;P&gt;To create the "No of Nights" column based on your described logic in Power BI using DAX:&lt;/P&gt;&lt;H3&gt;Logic Summary:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;TourRefNo&lt;/STRONG&gt;: Group by TourRefNo.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;SuppType&lt;/STRONG&gt;: Only consider SuppType = "HTL".&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;BookingDate&lt;/STRONG&gt;: Count the distinct BookingDate if there are &lt;STRONG&gt;two or more HTL entries&lt;/STRONG&gt; for a TourRefNo.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The "No of Nights" value should then apply to all rows within the same TourRefNo.&lt;/P&gt;&lt;H3&gt;DAX Solution:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Step 1&lt;/STRONG&gt;: Create a calculated column for counting distinct booking dates of "HTL":&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;HTL_BookingDatesCount = CALCULATE( DISTINCTCOUNT('Table'[BookingDate]), FILTER('Table', 'Table'[TourRefNo] = EARLIER('Table'[TourRefNo]) &amp;amp;&amp;amp; 'Table'[SuppType] = "HTL" ) )&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Step 2&lt;/STRONG&gt;: Create the "No of Nights" column based on the count of HTL booking dates:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;No_of_Nights = VAR HTL_Count = CALCULATE( COUNTROWS('Table'), FILTER('Table', 'Table'[TourRefNo] = EARLIER('Table'[TourRefNo]) &amp;amp;&amp;amp; 'Table'[SuppType] = "HTL" ) ) RETURN IF( HTL_Count &amp;gt;= 2, CALCULATE( DISTINCTCOUNT('Table'[BookingDate]), FILTER('Table', 'Table'[TourRefNo] = EARLIER('Table'[TourRefNo]) &amp;amp;&amp;amp; 'Table'[SuppType] = "HTL" ) ), 0 )&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;Explanation:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;HTL_BookingDatesCount&lt;/STRONG&gt;: Counts distinct BookingDate values for rows where SuppType = "HTL".&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;No_of_Nights&lt;/STRONG&gt;:&lt;UL&gt;&lt;LI&gt;Checks if there are at least two SuppType = "HTL" rows for a TourRefNo.&lt;/LI&gt;&lt;LI&gt;If true, calculates the distinct count of BookingDate for HTL rows under the same TourRefNo.&lt;/LI&gt;&lt;LI&gt;Otherwise, assigns 0.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;Outcome:&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;All rows for the same TourRefNo will display the calculated "No of Nights" based on the logic.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Let me know if you'd like additional help!&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2024 07:31:36 GMT</pubDate>
    <dc:creator>123abc</dc:creator>
    <dc:date>2024-12-10T07:31:36Z</dc:date>
    <item>
      <title>DAX Command- Need Help</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Command-Need-Help/m-p/4321010#M171551</link>
      <description>&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In above pic , there is some logic, But I unable to write proper DAX add column logic.&lt;BR /&gt;I want to add the column"No of Nights ", that takes the reference of Tour ref no, supp type and booking date. If tour ref has &amp;gt;=2 of count of supp type HTL, It takes dist.count of booking dates and indicates that number to all the supp type for Perticular Tour ref no.&lt;BR /&gt;&lt;BR /&gt;How can I do it...Please help&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 06:35:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Command-Need-Help/m-p/4321010#M171551</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-12-10T06:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Command- Need Help</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Command-Need-Help/m-p/4321158#M171554</link>
      <description>&lt;P&gt;To create the "No of Nights" column based on your described logic in Power BI using DAX:&lt;/P&gt;&lt;H3&gt;Logic Summary:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;TourRefNo&lt;/STRONG&gt;: Group by TourRefNo.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;SuppType&lt;/STRONG&gt;: Only consider SuppType = "HTL".&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;BookingDate&lt;/STRONG&gt;: Count the distinct BookingDate if there are &lt;STRONG&gt;two or more HTL entries&lt;/STRONG&gt; for a TourRefNo.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The "No of Nights" value should then apply to all rows within the same TourRefNo.&lt;/P&gt;&lt;H3&gt;DAX Solution:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Step 1&lt;/STRONG&gt;: Create a calculated column for counting distinct booking dates of "HTL":&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;HTL_BookingDatesCount = CALCULATE( DISTINCTCOUNT('Table'[BookingDate]), FILTER('Table', 'Table'[TourRefNo] = EARLIER('Table'[TourRefNo]) &amp;amp;&amp;amp; 'Table'[SuppType] = "HTL" ) )&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Step 2&lt;/STRONG&gt;: Create the "No of Nights" column based on the count of HTL booking dates:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;No_of_Nights = VAR HTL_Count = CALCULATE( COUNTROWS('Table'), FILTER('Table', 'Table'[TourRefNo] = EARLIER('Table'[TourRefNo]) &amp;amp;&amp;amp; 'Table'[SuppType] = "HTL" ) ) RETURN IF( HTL_Count &amp;gt;= 2, CALCULATE( DISTINCTCOUNT('Table'[BookingDate]), FILTER('Table', 'Table'[TourRefNo] = EARLIER('Table'[TourRefNo]) &amp;amp;&amp;amp; 'Table'[SuppType] = "HTL" ) ), 0 )&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;Explanation:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;HTL_BookingDatesCount&lt;/STRONG&gt;: Counts distinct BookingDate values for rows where SuppType = "HTL".&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;No_of_Nights&lt;/STRONG&gt;:&lt;UL&gt;&lt;LI&gt;Checks if there are at least two SuppType = "HTL" rows for a TourRefNo.&lt;/LI&gt;&lt;LI&gt;If true, calculates the distinct count of BookingDate for HTL rows under the same TourRefNo.&lt;/LI&gt;&lt;LI&gt;Otherwise, assigns 0.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;Outcome:&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;All rows for the same TourRefNo will display the calculated "No of Nights" based on the logic.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Let me know if you'd like additional help!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 07:31:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Command-Need-Help/m-p/4321158#M171554</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-12-10T07:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Command- Need Help</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Command-Need-Help/m-p/4322948#M171624</link>
      <description>&lt;P&gt;Thanks for the reply from 123abc&amp;nbsp;, please allow me to add some more information:&lt;BR /&gt;Hi&amp;nbsp; Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the var() function to store the result of an expression as a named variable, which can then be passed as a parameter to other metric expressions, saving code length and memory consumption.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/dax/var-dax" target="_blank"&gt;VAR keyword (DAX) - DAX | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;1. Create calculated column.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Number of Nights =
var _count=
CALCULATE(
    DISTINCTCOUNT('Table'[BookingDate]),
    FILTER('Table',
    [TourRefNo]=EARLIER('Table'[TourRefNo])&amp;amp;&amp;amp;[SuppType]="HTL"))
return
IF(
    _count=BLANK(),0,_count)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Min 2 night =
 IF(
    [Number of Nights]&amp;gt;=2,"y","n")&lt;/LI-CODE&gt;
&lt;P&gt;2. Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 06:00:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Command-Need-Help/m-p/4322948#M171624</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-12-11T06:00:06Z</dc:date>
    </item>
  </channel>
</rss>

