<?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 Dynamically Subtract Variable Days? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2905882#M94809</link>
    <description>&lt;P&gt;Thanks, but this results in a lot of additional rows and wrong dates. &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&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;</description>
    <pubDate>Tue, 15 Nov 2022 08:57:38 GMT</pubDate>
    <dc:creator>TimmK</dc:creator>
    <dc:date>2022-11-15T08:57:38Z</dc:date>
    <item>
      <title>How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2897802#M94287</link>
      <description>&lt;P&gt;For simplicity I have a table with the three columns "Order Key", "Date" and "Days".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use a DAX measure (or if this is not possible a calculated column) to subtract the days from the date for each row. Additionally, if the result of the calculation is a date that is on a Saturday another day should be subtracted and if it is a Sunday two additional days should be subtracted. How can I do this?&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;</description>
      <pubDate>Thu, 10 Nov 2022 14:48:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2897802#M94287</guid>
      <dc:creator>TimmK</dc:creator>
      <dc:date>2022-11-10T14:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2897919#M94291</link>
      <description>&lt;P&gt;You could create a measure like&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Adjusted date =
VAR ReferenceDate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR ReferenceDays =
    SELECTEDVALUE ( 'Table'[Days] )
VAR BaseDate = ReferenceDate - ReferenceDays
VAR Result =
    SWITCH ( WEEKDAY ( BaseDate ), 1, BaseDate - 2, 7, BaseDate - 1, BaseDate )
RETURN
    Result
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 10 Nov 2022 15:52:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2897919#M94291</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-11-10T15:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2903421#M94632</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt;&amp;nbsp;Ah, actually the last part unfortunately does not work as intended. For example, let us say the reference date is November 21, 2022 (Monday) and 3 days should be subtracted. Then based on your measure the result would be November 18, 2022 (Friday). However, it actually should be November 16, 2022 (Wednesday) because it should be 3 workdays earlier, which means November 21, 2022 - 2 weekend days - 3 workdays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help with a solution?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 10:25:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2903421#M94632</guid>
      <dc:creator>TimmK</dc:creator>
      <dc:date>2022-11-14T10:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2903604#M94651</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Adjusted date =
VAR ReferenceDate =
    SELECTEDVALUE ( 'Table'[Date] )
VAR ReferenceDays =
    SELECTEDVALUE ( 'Table'[Days] )
VAR BaseDate = ReferenceDate - ReferenceDays
VAR WorkingDaysDiff =
    NETWORKDAYS ( BaseDate, ReferenceDate )
VAR Result = BaseDate - ( ReferenceDays - WorkingDaysDiff )
RETURN
    Result
&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 14 Nov 2022 12:13:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2903604#M94651</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-11-14T12:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2903654#M94658</link>
      <description>&lt;DIV&gt;Try this:&lt;DIV&gt;&amp;nbsp;&lt;DIV&gt;Adjusted date =&lt;DIV&gt;VAR ReferenceDate =&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECTEDVALUE ( 'Table'[Date] )&lt;DIV&gt;VAR ReferenceDays =&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECTEDVALUE ( 'Table'[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;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 14 Nov 2022 12:40:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2903654#M94658</guid>
      <dc:creator>FreemanZ</dc:creator>
      <dc:date>2022-11-14T12:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2903893#M94675</link>
      <description>&lt;P&gt;This is what I get with the updated measure:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Almost there.&amp;nbsp;If the date is 2022-11-16 (WED) and 2 days should be subtracted then the result should be 2022-11-14 (MON) instead of 2022-11-15 (TUE). It seems that addtional 1 day needs to be subtracted for each row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, for example if the date is 2022-11-16 (WED) and 3 days should be subtracted then the result should be&amp;nbsp;2022-11-11 (FRI) instead of&amp;nbsp;2022-11-13 (SUN).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additional question: How can I remove the 30.12.1899 from the total?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your great help.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 14:41:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2903893#M94675</guid>
      <dc:creator>TimmK</dc:creator>
      <dc:date>2022-11-14T14:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2905882#M94809</link>
      <description>&lt;P&gt;Thanks, but this results in a lot of additional rows and wrong dates. &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&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;</description>
      <pubDate>Tue, 15 Nov 2022 08:57:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2905882#M94809</guid>
      <dc:creator>TimmK</dc:creator>
      <dc:date>2022-11-15T08:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2906374#M94832</link>
      <description>&lt;P&gt;I think maybe a different approach. Add a column to your date table, Is Working Day, which returns 1 if the day is not a weekend. Then you can create a measure like&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Adjusted date =
IF (
    ISINSCOPE ( 'Table'[Date] ),
    VAR ReferenceDate =
        SELECTEDVALUE ( 'Table'[Date] )
    VAR ReferenceDays =
        SELECTEDVALUE ( 'Table'[Days] )
    VAR WorkingDates =
        CALCULATETABLE (
            TOPN ( ReferenceDays, 'Date', 'Date'[Date], DESC ),
            'Date'[Date] &amp;lt; ReferenceDate,
            'Date'[Is Working Day] = 1
        )
    RETURN
        MINX ( WorkingDates, 'Date'[Date] )
)
&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Nov 2022 11:29:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2906374#M94832</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-11-15T11:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2906803#M94859</link>
      <description>&lt;P&gt;This seems to have the correct result. Yet, when I add the measure to the table it loads a very long time. In another table (that has some more rows, 15 to be exact) it does not work at all, after a while I receive the error message "There's not enough memory to complete this operation.".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any possibility to improve the performance or maybe another solution?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 14:33:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2906803#M94859</guid>
      <dc:creator>TimmK</dc:creator>
      <dc:date>2022-11-15T14:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to Dynamically Subtract Variable Days?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2907213#M94896</link>
      <description>&lt;P&gt;I think you could adapt the technique from&amp;nbsp;&lt;A href="https://www.youtube.com/watch?v=2HkBbqxBzF0" target="_self"&gt;https://www.youtube.com/watch?v=2HkBbqxBzF0&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 16:50:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/How-to-Dynamically-Subtract-Variable-Days/m-p/2907213#M94896</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2022-11-15T16:50:51Z</dc:date>
    </item>
  </channel>
</rss>

