<?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: How to &amp;quot;flatten&amp;quot; a variable into constant? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2907653#M94914</link>
    <description>&lt;P&gt;File attached&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2022 19:51:41 GMT</pubDate>
    <dc:creator>daXtreme</dc:creator>
    <dc:date>2022-11-15T19:51:41Z</dc:date>
    <item>
      <title>How to "flatten" a variable into constant?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2906013#M94816</link>
      <description>&lt;P&gt;Hello All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 curves that contains a low and high case sales scenario.&amp;nbsp; I would like to find the ratio between these 2 curves (&lt;STRONG&gt;Sales High / Sales Low&lt;/STRONG&gt;) on the date of the latest monthly actual sales.&amp;nbsp; I then want to use this ratio as a constant to multiply &lt;STRONG&gt;Sales Low&lt;/STRONG&gt;&amp;nbsp;over a range of dates.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Test_Measure =
VAR _eval_date =
    CALCULATE ( MAXX ( ALLSELECTED ( Actual_Sales ), [date] ) ) // Finds latest sales date 
VAR _date =
    // If latest sales date is older than 2 months, it will default back to current month.  
    CALCULATE (
        IF (
            _eval_date
                &amp;lt; DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 ),
            DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ),
            _eval_date
        )
    )
VAR _sales_high =
    CALCULATE (
        // Value of sales high curve @ _date
        MAX ( Sales_High[sales] ),
        FILTER ( Sales_High, Sales_High[date] = _date )
    )
VAR _sales_low =
    CALCULATE (
        // Value of sales low curve @ _date
        MAX ( Sales_Low[sales] ),
        FILTER ( Sales_Low, Sales_Low[date] = _date )
    )
VAR _ratio =
    DIVIDE ( _sales_low, _sales_high ) // Ratio of Sales Low/Sales High
RETURN
    IF (
        MIN ( Sales_Low[date] ) &amp;gt;= _date,
        CALCULATE ( SUM ( Sales_Low[sales] ) * _ratio )
    )
// Multiply the Sales Low curve by _ratio for all future dates&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've included a sample file below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A title="Sample File" href="https://1drv.ms/u/s!AndVpJp2VQectB6-RLt98SCjS8ci?e=oVWPpL" target="_self"&gt;Sample File Link&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Lets say I get &lt;STRONG&gt;_ratio = 1.57&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;I would expect to get "&lt;STRONG&gt;Projected Sales&lt;/STRONG&gt;" in the first figure as my final result.&amp;nbsp; Instead I get the below figure, where I only have a single value.&amp;nbsp; The curve in the first figure was made by replacing "&lt;STRONG&gt;SUM(Sales_Low[sales]) * _ratio&lt;/STRONG&gt;" with "&lt;STRONG&gt;SUM(Sales_Low[sales]) &lt;/STRONG&gt;&lt;STRONG&gt;* 1.57&lt;/STRONG&gt;" meaning &lt;STRONG&gt;_ratio&lt;/STRONG&gt; isnt actually a constant.&amp;nbsp; &amp;nbsp;I assume it has to do with the&amp;nbsp;"&lt;STRONG&gt;IF Sales_Low[date] &amp;gt;= _date&lt;/STRONG&gt;" condition.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;img /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;BR /&gt;Is there any way for me to 'flatten' the variable into a constant (1.57) that is invariable for all dates a.k.a. hardcode it?&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm still very new to DAX so any additional advice and suggestions are very welcome.&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 15 Nov 2022 15:24:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2906013#M94816</guid>
      <dc:creator>Palmtop</dc:creator>
      <dc:date>2022-11-15T15:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to "flatten" a variable into constant?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2906672#M94851</link>
      <description>&lt;P&gt;First, I'd suggest you follow the rules for DAX formatting:&amp;nbsp;&lt;A href="https://www.sqlbi.com/articles/rules-for-dax-code-formatting/" target="_blank"&gt;Rules for DAX Code Formatting - SQLBI&lt;/A&gt;. DAX that's not formatted the right way is not DAX (and many specialist don't even look at such code).&amp;nbsp;Second, I'd suggest you paste something that can be tinkered with and copied. Nobody wants to type text in from a picture. Third, I'd also kindly suggest that you create a sample file which demonstrates the issue and paste a link to it here so that it's easier for us to troubleshoot. The file should be stored on a shared drive and have public access rights.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 13:40:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2906672#M94851</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-11-15T13:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to "flatten" a variable into constant?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2906986#M94878</link>
      <description>&lt;P&gt;Hello daXtreme,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the advice.&amp;nbsp; I've edited my post with the formatted DAX measure and a link to a sample file.&amp;nbsp; Let me know if anyone has difficulties accessing it.&amp;nbsp; Otherwise, I hope this is a good starting spot to help solve the issue.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 15:28:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2906986#M94878</guid>
      <dc:creator>Palmtop</dc:creator>
      <dc:date>2022-11-15T15:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to "flatten" a variable into constant?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2907282#M94901</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="456186" data-lia-user-login="Palmtop" class="lia-mention lia-mention-user"&gt;Palmtop&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's much, much better now &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 17:19:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2907282#M94901</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-11-15T17:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to "flatten" a variable into constant?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2907653#M94914</link>
      <description>&lt;P&gt;File attached&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 19:51:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2907653#M94914</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-11-15T19:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to "flatten" a variable into constant?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2909621#M95046</link>
      <description>&lt;P&gt;Hi daXtreme,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you, it worked like a charm.&amp;nbsp; I appreciate all the help and patience.&amp;nbsp; Also the clode cleanup is very welcomed &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read through the date table page from PowerBI -&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-date-tables" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-date-tables&lt;/A&gt;&lt;/P&gt;&lt;P&gt;but still don't fully understand why is it exactly that auto-generated hierarchies in my initial model caused the issues it did, and how getting rid of them by making a date table fixed the issues.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 13:32:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2909621#M95046</guid>
      <dc:creator>Palmtop</dc:creator>
      <dc:date>2022-11-16T13:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to "flatten" a variable into constant?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2909628#M95047</link>
      <description>&lt;P&gt;That's not exactly correct. It's not the auto-gen hierarchies that were the issue. It's the fields that were. You used the wrong fields from the wrong tables. As for the auto-gen hierarchies... JUST DON'T EVER USE THEM. Forget they exist. Always create your own Date tables. ALWAYS. Take this advice or suffer. Easy as that.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 13:31:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-quot-flatten-quot-a-variable-into-constant/m-p/2909628#M95047</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-11-16T13:31:56Z</dc:date>
    </item>
  </channel>
</rss>

