<?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: EARLIER Function in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775409#M3911</link>
    <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="165232" data-lia-user-login="Destrogiro" class="lia-mention lia-mention-user"&gt;Destrogiro&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not clear what you need. What is the code supposed to do? Is it a measure, a calc column? Can you show a sample of your data with an example explaining the expected result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please &lt;STRONG&gt;always&lt;/STRONG&gt; show your sample data in &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;text-tabular format&lt;/FONT&gt;&lt;/STRONG&gt; in addition to (or instead of) the screen captures. A screen cap doesn't allow people to readily copy the data and run a quick test and thus decreases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).&lt;/P&gt;</description>
    <pubDate>Mon, 26 Aug 2019 08:01:49 GMT</pubDate>
    <dc:creator>AlB</dc:creator>
    <dc:date>2019-08-26T08:01:49Z</dc:date>
    <item>
      <title>EARLIER Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775389#M3910</link>
      <description>&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;I'm new to Power BI and I'm having trouble with EARLIER function. Basically what I need is:&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;ValorTotal = SWITCH(TCBLBI_Peso_Empresas_Tradadas[OrdemGrupo];&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;2; EARLIER([Valor];1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5; EARLIER([Valor];1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7; EARLIER([Valor];1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3; EARLIER([Valor];2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 6; EARLIER([Valor];2);&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9; EARLIER([Valor];2); 0)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;But I'm getting this error message: EARLIER/EARLIEST refers to an earlier row context which doesn't exist.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;Is there a way to do this?&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="x_MsoNormal"&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 07:52:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775389#M3910</guid>
      <dc:creator>Destrogiro</dc:creator>
      <dc:date>2019-08-26T07:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: EARLIER Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775409#M3911</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="165232" data-lia-user-login="Destrogiro" class="lia-mention lia-mention-user"&gt;Destrogiro&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not clear what you need. What is the code supposed to do? Is it a measure, a calc column? Can you show a sample of your data with an example explaining the expected result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please &lt;STRONG&gt;always&lt;/STRONG&gt; show your sample data in &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;text-tabular format&lt;/FONT&gt;&lt;/STRONG&gt; in addition to (or instead of) the screen captures. A screen cap doesn't allow people to readily copy the data and run a quick test and thus decreases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 08:01:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775409#M3911</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2019-08-26T08:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: EARLIER Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775441#M3912</link>
      <description>&lt;P&gt;Here is an example of what I need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GroupOrder&amp;nbsp; &amp;nbsp; Value 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Value 2&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;---------------------------------------------------------------------------------------------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;322762272703.0400&amp;nbsp; &amp;nbsp; &amp;nbsp;0.0000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;504993049586.4000&amp;nbsp; &amp;nbsp; &amp;nbsp;322762272703.0400&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;117421034783.7100&amp;nbsp; &amp;nbsp; &amp;nbsp;322762272703.0400&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;725451720271.6600&amp;nbsp; &amp;nbsp; &amp;nbsp;0.0000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1527350829053.5900&amp;nbsp; &amp;nbsp; 725451720271.6600&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;90925867161.1700&amp;nbsp; &amp;nbsp; &amp;nbsp; 725451720271.6600&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;405811.0000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.0000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;105.0000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 405811.0000&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;20121231&amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;27.0000&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;405811.0000&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When GroupOrder is 1,4,7 Value 2 should be 0&lt;/P&gt;&lt;P&gt;When GroupOrder is (2,5,8) Value 2 should have EARLIER(Value 1,1)&lt;/P&gt;&lt;P&gt;When GroupOrder is (3,6,9) Value 2 should have EARLIER(Value 1,2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was able to do it in SQL Server using LAG function. I don't know if it helps, but here is the SQL code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;SELECT DataReferencia, OrdemGrupo, GrupoInformacao, TipoInformacao, Valor AS ValorAtual,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;CASE WHEN OrdemGrupo IN (2,5,8) THEN LAG(Valor,1,0) OVER (ORDER BY DataReferencia, OrdemGrupo, GrupoInformacao, TipoInformacao)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;WHEN OrdemGrupo IN (3,6,9) THEN LAG(Valor,2,0) OVER (ORDER BY DataReferencia, OrdemGrupo, GrupoInformacao, TipoInformacao)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;ELSE 0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;END AS ValorTotal&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;FROM TCBLBI_Peso_Empresas_Tradadas&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" size="2"&gt;WHERE DataReferencia = 20121231&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 08:41:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775441#M3912</guid>
      <dc:creator>Destrogiro</dc:creator>
      <dc:date>2019-08-26T08:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: EARLIER Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775508#M3913</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="165232" data-lia-user-login="Destrogiro" class="lia-mention lia-mention-user"&gt;Destrogiro&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EARLIER works in a completely different way from what you seem to be assuming. It gives you access to the outer &lt;STRONG&gt;row context&lt;/STRONG&gt;, not to the previous row.&amp;nbsp; Try this for your calculated column, where I'm assuming you need this done by date:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Value2 =
SWITCH (
    TRUE (),
    Table1[GroupOrder] IN { 1, 4, 7 }, 0,
    Table1[GroupOrder] IN { 2, 5, 8 }, CALCULATE (
        DISTINCT ( Table1[Value 1] ),
        Table1[GroupOrder]
            = ( EARLIER ( Table1[GroupOrder] ) - 1 ),
        ALLEXCEPT ( Table1, Table1[Date] )
    ),
    Table1[GroupOrder] IN { 3, 6, 9 }, CALCULATE (
        DISTINCT ( Table1[Value 1] ),
        Table1[GroupOrder]
            = ( EARLIER ( Table1[GroupOrder] ) - 2 ),
        ALLEXCEPT ( Table1, Table1[Date] )
    )
)
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 09:28:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775508#M3913</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2019-08-26T09:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: EARLIER Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775522#M3914</link>
      <description>&lt;P&gt;Since the introduction of VAR, there's no actual need for EARLIER any longer.&amp;nbsp; So you might want to do it in a&amp;nbsp;different way, perhaps easier to follow conceptually, and forget about EARLIER altogether (which is actually recommended nowadays):&lt;/P&gt;
&lt;PRE&gt;Value2 =
SWITCH (
    TRUE (),
    Table1[GroupOrder] IN { 1, 4, 7 }, 0,
    Table1[GroupOrder] IN { 2, 5, 8 },
    VAR PreviousGroupOrder_ = Table1[GroupOrder] - 1
    RETURN
        CALCULATE (
            DISTINCT ( Table1[Value 1] ),
            Table1[GroupOrder] = PreviousGroupOrder_,
            ALLEXCEPT ( Table1, Table1[Date] )
        ),
    Table1[GroupOrder] IN { 3, 6, 9 },
    VAR PreviousGroupOrder2_ = Table1[GroupOrder] - 2
    RETURN
        CALCULATE (
            DISTINCT ( Table1[Value 1] ),
            Table1[GroupOrder] = PreviousGroupOrder2_,
            ALLEXCEPT ( Table1, Table1[Date] )
        )
)
&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Aug 2019 09:35:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775522#M3914</guid>
      <dc:creator>AlB</dc:creator>
      <dc:date>2019-08-26T09:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: EARLIER Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775557#M3915</link>
      <description>&lt;P&gt;Thank you very much, &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="92178" data-lia-user-login="AlB" class="lia-mention lia-mention-user"&gt;AlB&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;It solved my problem!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Aug 2019 09:57:24 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/EARLIER-Function/m-p/775557#M3915</guid>
      <dc:creator>Destrogiro</dc:creator>
      <dc:date>2019-08-26T09:57:24Z</dc:date>
    </item>
  </channel>
</rss>

