<?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: Exclude Weekend from Dynamic Subtraction in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2909638#M95048</link>
    <description>&lt;P&gt;Well, the error message is clear. This line&lt;/P&gt;
&lt;PRE class=""&gt;&lt;CODE&gt;CALENDAR( CurrentDate - DaysToSubtract - 50, CurrentDate ),&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;apparently receives something that's not allowed. Investigate this in DAX Studio and fix it. Something is probably wrong with CurrentDate which is set by your code to BLANK. Sorry, I can't help you with this as I don't have your data. You have to troubleshoot by yourself.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Nov 2022 13:35:22 GMT</pubDate>
    <dc:creator>daXtreme</dc:creator>
    <dc:date>2022-11-16T13:35:22Z</dc:date>
    <item>
      <title>Exclude Weekend from Dynamic Subtraction</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2905933#M94811</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;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use a DAX measure to subtract the days from the date for each row. For instance, if date = 2022-11-16 (WED) and days = 2 then the result should be 2022-11-14 (MON).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As for the production only workdays matter, the weekend should be generally excluded.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;Date = 2022-11-16 (WED); Days = 3 then the result should be 2022-11-11 (FRI)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Date = 2022-11-21 (MON); Days = 3 then the result should be 2022-11-16 (WED)&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following measure, but it does not work fully correctly:&lt;/P&gt;&lt;PRE&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;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 10:09:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2905933#M94811</guid>
      <dc:creator>TimmK</dc:creator>
      <dc:date>2022-11-15T10:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude Weekend from Dynamic Subtraction</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2906679#M94854</link>
      <description>&lt;P&gt;So then... I'm confused. What do you need, a calculated column or a measure?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 13:45:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2906679#M94854</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-11-15T13:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude Weekend from Dynamic Subtraction</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2906683#M94855</link>
      <description>&lt;P&gt;A measure, but if this is not possible then a calculated column.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 13:48:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2906683#M94855</guid>
      <dc:creator>TimmK</dc:creator>
      <dc:date>2022-11-15T13:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude Weekend from Dynamic Subtraction</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2906828#M94860</link>
      <description>&lt;LI-CODE lang="csharp"&gt;// Run this in DAX Studio to see how it works.

define table TestTable =
    selectcolumns(
        {
            (1, dt"2022-12-01", 5),
            (2, dt"2022-12-05", 3),
            (3, dt"2022-12-01", 3),
            (4, dt"2022-12-03", 2),
            (1, dt"2022-12-10", 5)
        },
        "OrderKey", [Value1],
        "Date", [Value2],
        "Day", format( [Value2], "dddd" ),
        "Days", [Value3]
    )
EVALUATE
    ADDCOLUMNS(
        TestTable,
        "@DateWithDaysSubtracted",
            // Please make sure that the number of days to
            // go back is not more than 50. If it is, this
            // code must be adjusted. This is the code for
            // the calculated column.
            var CurrentDate = TestTable[Date]
            var DaysToSubtract = TestTable[Days]
            var AuxiliaryDateTableWithoutWeekeds =
                SELECTCOLUMNS(
                    FILTER(
                        CALENDAR( CurrentDate - DaysToSubtract - 50, CurrentDate ),
                        WEEKDAY( [Date], 2 ) IN {1, 2, 3, 4, 5}
                    ),
                    "@CalendarDate", [Date]
                )
            var DatesWithRanks =
                ADDCOLUMNS(
                    AuxiliaryDateTableWithoutWeekeds,
                    "@Rank",
                        var RunningDate = [@CalendarDate]
                        var Ranking =
                            RANKX(
                                AuxiliaryDateTableWithoutWeekeds,
                                [@CalendarDate],
                                RunningDate,
                                DESC
                            ) - 1 // so that the ranks start with 0
                        return
                            Ranking
                )
            var Result =
                MAXX(
                    Filter(
                        DatesWithRanks,
                        [@Rank] = DaysToSubtract
                    ),
                    [@CalendarDate]
                )
            return
                Result
    )&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Nov 2022 14:39:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2906828#M94860</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-11-15T14:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude Weekend from Dynamic Subtraction</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2906834#M94862</link>
      <description>&lt;P&gt;If the number of days to go back is set in stone for any single value of the date, then creating a calculated column makes more sense because this is not a dynamic calculation. In any case, once you've got this calc column, you can create a measure based on it.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 13:36:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2906834#M94862</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-11-16T13:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude Weekend from Dynamic Subtraction</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2909232#M95018</link>
      <description>&lt;P&gt;I created a new table and inserted the following adapted code:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ADDCOLUMNS(
        Screen,
        "@DateWithDaysSubtracted",
            // Please make sure that the number of days to
            // go back is not more than 50. If it is, this
            // code must be adjusted. This is the code for
            // the calculated column.
            var CurrentDate = Screen[Date]
            var DaysToSubtract = Screen[Days]
            var AuxiliaryDateTableWithoutWeekeds =
                SELECTCOLUMNS(
                    FILTER(
                        CALENDAR( CurrentDate - DaysToSubtract - 50, CurrentDate ),
                        WEEKDAY( [Date], 2 ) IN {1, 2, 3, 4, 5}
                    ),
                    "@CalendarDate", [Date]
                )
            var DatesWithRanks =
                ADDCOLUMNS(
                    AuxiliaryDateTableWithoutWeekeds,
                    "@Rank",
                        var RunningDate = [@CalendarDate]
                        var Ranking =
                            RANKX(
                                AuxiliaryDateTableWithoutWeekeds,
                                [@CalendarDate],
                                RunningDate,
                                DESC
                            ) - 1 // so that the ranks start with 0
                        return
                            Ranking
                )
            var Result =
                MAXX(
                    Filter(
                        DatesWithRanks,
                        [@Rank] = DaysToSubtract
                    ),
                    [@CalendarDate]
                )
            return
                Result
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I unfortunately get the error message "The start date or end date in Calendar function can not be Blank value.".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My original table is "Screen" that includes the columns [OrderKey], [Date], [Day] and [Days].&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 11:05:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2909232#M95018</guid>
      <dc:creator>TimmK</dc:creator>
      <dc:date>2022-11-16T11:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude Weekend from Dynamic Subtraction</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2909638#M95048</link>
      <description>&lt;P&gt;Well, the error message is clear. This line&lt;/P&gt;
&lt;PRE class=""&gt;&lt;CODE&gt;CALENDAR( CurrentDate - DaysToSubtract - 50, CurrentDate ),&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;apparently receives something that's not allowed. Investigate this in DAX Studio and fix it. Something is probably wrong with CurrentDate which is set by your code to BLANK. Sorry, I can't help you with this as I don't have your data. You have to troubleshoot by yourself.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 13:35:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Exclude-Weekend-from-Dynamic-Subtraction/m-p/2909638#M95048</guid>
      <dc:creator>daXtreme</dc:creator>
      <dc:date>2022-11-16T13:35:22Z</dc:date>
    </item>
  </channel>
</rss>

