<?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: Dynamic Calculated column with a lag value of another column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332283#M23614</link>
    <description>&lt;P&gt;Thanks David, actually posted this more than a month back &amp;amp; was able to acheive it in a different way. I appreciate your effort to answer a ques so long down in the queue &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CFR (Deaths/Total Cases X Days Ago) = SWITCH(SELECTEDVALUE('Days Lag Tbl'[Lag Days]),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;7,IFERROR(DIVIDE(CALCULATE(SUM('Main Tbl'[Cumulative Deaths])),CALCULATE(SUM('Main Tbl'[Cumulative Cases]),DATEADD('Main Tbl'[Date],-7,DAY))),0),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;14, IFERROR(DIVIDE(CALCULATE(SUM('Main Tbl'[Cumulative Deaths])),CALCULATE(SUM('Main Tbl'[Cumulative Cases]),DATEADD('Main Tbl'[Date],-14,DAY))),0),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;21,IFERROR(DIVIDE(CALCULATE(SUM('Main Tbl'[Cumulative Deaths])),CALCULATE(SUM('Main Tbl'[Cumulative Cases]),DATEADD('Main Tbl'[Date],-21,DAY))),0),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;30,IFERROR(DIVIDE(CALCULATE(SUM('Main Tbl'[Cumulative Deaths])),CALCULATE(SUM('Main Tbl'[Cumulative Cases]),DATEADD('Main Tbl'[Date],-30,DAY))),0))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 28 Aug 2020 14:42:22 GMT</pubDate>
    <dc:creator>vikrantarora25</dc:creator>
    <dc:date>2020-08-28T14:42:22Z</dc:date>
    <item>
      <title>Dynamic Calculated column with a lag value of another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1192065#M18862</link>
      <description>&lt;P&gt;Hi PBI Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table having a columns for Date, Country &amp;amp; Deaths plus some other columns. Each value in Deaths column represents total/cumulative deaths as on that date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have a dymanic calculated column which is based on a slicer value and provides total deaths with a lag of X days, where X days is a value based on slicer selection. Below is the DAX formula i have used which successfully gives 7 days lag values, but instead of this fixed 7 days I want a dynamic value to be subtracted after earlier function based on a slicer selection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using whatif parameter but it does not work for a calculated column, any thoughts how I can achieve a dynamic calculated column based on slicers?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Deaths 7 Days Ago = MAXX(FILTER('Main Tbl','Main Tbl'[Country/Region]=EARLIER('Main Tbl'[Country/Region]) &amp;amp;&amp;amp;
'Main Tbl'[Date]=EARLIER('Main Tbl'[Date])-7),
'Main Tbl'[Deaths])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my table, let me know if more info is needed to solve this.&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;Regards&lt;/P&gt;&lt;P&gt;Vikrant&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jun 2020 11:30:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1192065#M18862</guid>
      <dc:creator>vikrantarora25</dc:creator>
      <dc:date>2020-06-30T11:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Calculated column with a lag value of another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332093#M23600</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="242403" data-lia-user-login="vikrantarora25" class="lia-mention lia-mention-user"&gt;vikrantarora25&lt;/a&gt; -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First off, you cannot do this as a calculated column as those do not re-calculate when a slicer or filter is applied. You want to code this as a measure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being said, you can access the value selected on a slicer with SELECTEDVALUE(Slicer[Column]), making your code something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Deaths 7 Days Ago =
VAR __Lag =
    SELECTEDVALUE ( Slicer[Column] )
RETURN
    MAXX (
        FILTER (
            'Main Tbl',
            'Main Tbl'[Country/Region] = EARLIER ( 'Main Tbl'[Country/Region] )
                &amp;amp;&amp;amp; 'Main Tbl'[Date]
                    = EARLIER ( 'Main Tbl'[Date] ) - __Lag
        ),
        'Main Tbl'[Deaths]
    )
&lt;/LI-CODE&gt;
&lt;P&gt;To then make this a "column", just add it along with the other pertinent data from Main Tbl into a table visual.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 13:13:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332093#M23600</guid>
      <dc:creator>dedelman_clng</dc:creator>
      <dc:date>2020-08-28T13:13:28Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Calculated column with a lag value of another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332283#M23614</link>
      <description>&lt;P&gt;Thanks David, actually posted this more than a month back &amp;amp; was able to acheive it in a different way. I appreciate your effort to answer a ques so long down in the queue &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;CFR (Deaths/Total Cases X Days Ago) = SWITCH(SELECTEDVALUE('Days Lag Tbl'[Lag Days]),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;7,IFERROR(DIVIDE(CALCULATE(SUM('Main Tbl'[Cumulative Deaths])),CALCULATE(SUM('Main Tbl'[Cumulative Cases]),DATEADD('Main Tbl'[Date],-7,DAY))),0),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;14, IFERROR(DIVIDE(CALCULATE(SUM('Main Tbl'[Cumulative Deaths])),CALCULATE(SUM('Main Tbl'[Cumulative Cases]),DATEADD('Main Tbl'[Date],-14,DAY))),0),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;21,IFERROR(DIVIDE(CALCULATE(SUM('Main Tbl'[Cumulative Deaths])),CALCULATE(SUM('Main Tbl'[Cumulative Cases]),DATEADD('Main Tbl'[Date],-21,DAY))),0),&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;30,IFERROR(DIVIDE(CALCULATE(SUM('Main Tbl'[Cumulative Deaths])),CALCULATE(SUM('Main Tbl'[Cumulative Cases]),DATEADD('Main Tbl'[Date],-30,DAY))),0))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 28 Aug 2020 14:42:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332283#M23614</guid>
      <dc:creator>vikrantarora25</dc:creator>
      <dc:date>2020-08-28T14:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Calculated column with a lag value of another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332288#M23615</link>
      <description>&lt;P&gt;Glad to know you got it working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One additional point of interest - DIVIDE() has its own built-in error handling, so you should not need IFERROR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DIVIDE( Numerator, Denominator, AlternateResult [if Denominator is 0]&amp;nbsp; )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 14:47:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332288#M23615</guid>
      <dc:creator>dedelman_clng</dc:creator>
      <dc:date>2020-08-28T14:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic Calculated column with a lag value of another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332303#M23617</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="242403" data-lia-user-login="vikrantarora25" class="lia-mention lia-mention-user"&gt;vikrantarora25&lt;/a&gt;&amp;nbsp; You can remove IFERROR because DIVIDE will take care of it, also instead of using SUM () multiple times, create a separate measure for it, hence increasing readability :&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;Total Deaths =
SUM ( 'Main Tbl'[Cumulative Cases] )
&lt;/LI-CODE&gt;&lt;LI-CODE lang="php"&gt;CFR (Deaths/Total Cases X Days Ago) =
SWITCH (
    SELECTEDVALUE ( 'Days Lag Tbl'[Lag Days] ),
    7,
        DIVIDE (
            [Total Deaths],
            CALCULATE ( [Total Deaths], DATEADD ( 'Main Tbl'[Date], -7, DAY ) )
        ),
    14,
        DIVIDE (
            [Total Deaths],
            CALCULATE ( [Total Deaths], DATEADD ( 'Main Tbl'[Date], -14, DAY ) )
        ),
    21,
        DIVIDE (
            [Total Deaths],
            CALCULATE ( [Total Deaths], DATEADD ( 'Main Tbl'[Date], -21, DAY ) )
        ),
    30,
        DIVIDE (
            [Total Deaths],
            CALCULATE ( [Total Deaths], DATEADD ( 'Main Tbl'[Date], -30, DAY ) )
        )
)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Aug 2020 14:57:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dynamic-Calculated-column-with-a-lag-value-of-another-column/m-p/1332303#M23617</guid>
      <dc:creator>AntrikshSharma</dc:creator>
      <dc:date>2020-08-28T14:57:34Z</dc:date>
    </item>
  </channel>
</rss>

