<?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: If Statements for last week in Direct Query grabbing all years in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670568#M142376</link>
    <description>&lt;P&gt;&lt;SPAN&gt;When I entered it into DAX, it says that there are too many arguments passed in this section:&lt;BR /&gt;||&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AND (&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MONTH ( DimDate[Date] ) = 12,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MONTH ( TODAY() ) = 1,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;YEAR ( DimDate[Date] ) = YEAR ( TODAY() ) - 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2024 14:46:22 GMT</pubDate>
    <dc:creator>PhazeRCIL</dc:creator>
    <dc:date>2024-01-31T14:46:22Z</dc:date>
    <item>
      <title>If Statements for last week in Direct Query grabbing all years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670428#M142350</link>
      <description>&lt;P&gt;Hello, I am trying to add a column in my date calendar that says Yes if the week is last week compared to TODAY:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;IsLastWeek =&lt;/SPAN&gt; &lt;SPAN&gt;IF&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;AND&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;WEEKNUM&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;DimDate&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;)= &lt;/SPAN&gt;&lt;SPAN&gt;WEEKNUM&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;TODAY&lt;/SPAN&gt;&lt;SPAN&gt;()) - &lt;/SPAN&gt;&lt;SPAN&gt;1&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;YEAR&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;DimDate&lt;/SPAN&gt;&lt;SPAN&gt;[Date]&lt;/SPAN&gt;&lt;SPAN&gt;) = &lt;/SPAN&gt;&lt;SPAN&gt;YEAR&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;TODAY&lt;/SPAN&gt;&lt;SPAN&gt;())), &lt;/SPAN&gt;&lt;SPAN&gt;"Yes"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"No"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The limitations of this code is that if the week overlaps into the previous year, I don't have that data. But if I go without the Year filter, the function grabs ALL last weeks of every year in my data calendar.&lt;BR /&gt;&lt;BR /&gt;I need to have my storage mode set to DirectQuery to have realtime data displays so I can't normally use the FORMAT function to format Today and DimDate[Date] to the week number&lt;BR /&gt;&lt;BR /&gt;Any advice would be great!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 31 Jan 2024 13:48:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670428#M142350</guid>
      <dc:creator>PhazeRCIL</dc:creator>
      <dc:date>2024-01-31T13:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements for last week in Direct Query grabbing all years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670469#M142358</link>
      <description>&lt;P&gt;&lt;SPAN&gt;To handle the issue you're encountering with DirectQuery mode and the limitations of the IsLastWeek&lt;SPAN&gt; column, you can adjust your approach to calculate the last week dynamically without relying on the YEAR&lt;SPAN&gt; function. One way to achieve this is by comparing the date ranges directly. Here's how you can do it:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;IsLastWeek =&lt;BR /&gt;IF (&lt;BR /&gt;AND (&lt;BR /&gt;DimDate[Date] &amp;gt;= TODAY() - WEEKDAY(TODAY()) - 6,&lt;BR /&gt;DimDate[Date] &amp;lt; TODAY() - WEEKDAY(TODAY()) + 1&lt;BR /&gt;),&lt;BR /&gt;"Yes",&lt;BR /&gt;"No"&lt;BR /&gt;)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To handle the issue you're encountering with DirectQuery mode and the limitations of the IsLastWeek column, you can adjust your approach to calculate the last week dynamically without relying on the YEAR function. One way to achieve this is by comparing the date ranges directly. Here's how you can do it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN&gt;DAX&lt;SPAN class=""&gt;Copy code&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;DIV class=""&gt;IsLastWeek = IF ( AND ( DimDate[Date] &amp;gt;= TODAY() - WEEKDAY(TODAY()) - 6, DimDate[Date] &amp;lt; TODAY() - WEEKDAY(TODAY()) + 1 ), "Yes", "No" )&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;Explanation:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;WEEKDAY(TODAY()) gives you the numeric representation of the current day of the week (e.g., Sunday is 1, Monday is 2, etc.).&lt;/LI&gt;&lt;LI&gt;TODAY() - WEEKDAY(TODAY()) + 1 gives you the first day (Sunday) of the current week.&lt;/LI&gt;&lt;LI&gt;TODAY() - WEEKDAY(TODAY()) - 6 gives you the last day (Saturday) of the previous week.&lt;P&gt;Therefore, the condition DimDate[Date] &amp;gt;= TODAY() - WEEKDAY(TODAY()) - 6 checks if the date falls after the last day of the previous week, and DimDate[Date] &amp;lt; TODAY() - WEEKDAY(TODAY()) + 1 checks if the date falls before the first day of the current week.&lt;/P&gt;&lt;P&gt;This approach dynamically calculates the last week without relying on the year. It should work regardless of the year transition. Make sure your date table (DimDate) includes all the necessary dates for your analysis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 31 Jan 2024 14:06:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670469#M142358</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-01-31T14:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements for last week in Direct Query grabbing all years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670517#M142366</link>
      <description>&lt;P&gt;Thanks! I worked just as I wanted!!&lt;BR /&gt;How would you go about doing the same thing but for the previous month?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 14:23:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670517#M142366</guid>
      <dc:creator>PhazeRCIL</dc:creator>
      <dc:date>2024-01-31T14:23:10Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements for last week in Direct Query grabbing all years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670535#M142368</link>
      <description>&lt;P&gt;&lt;SPAN&gt;To determine if a date belongs to the previous month, you can compare the month and year of the date with the month and year of the previous month. Here's how you can adjust your formula to achieve this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;IsPreviousMonth =&lt;BR /&gt;IF (&lt;BR /&gt;AND (&lt;BR /&gt;MONTH ( DimDate[Date] ) = MONTH ( TODAY() ) - 1,&lt;BR /&gt;YEAR ( DimDate[Date] ) = YEAR ( TODAY() )&lt;BR /&gt;)&lt;BR /&gt;||&lt;BR /&gt;AND (&lt;BR /&gt;MONTH ( DimDate[Date] ) = 12,&lt;BR /&gt;MONTH ( TODAY() ) = 1,&lt;BR /&gt;YEAR ( DimDate[Date] ) = YEAR ( TODAY() ) - 1&lt;BR /&gt;),&lt;BR /&gt;"Yes",&lt;BR /&gt;"No"&lt;BR /&gt;)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this formula:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The MONTH() function extracts the month number from the date.&lt;/LI&gt;&lt;LI&gt;The YEAR() function extracts the year from the date.&lt;/LI&gt;&lt;LI&gt;We check if the month of the date is one less than the current month, and if the year matches the current year.&lt;/LI&gt;&lt;LI&gt;Additionally, we handle the case where the date is in December and the current month is January of the next year, signifying the last month of the previous year overlapping with the first month of the current year.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This adjusted formula should correctly identify whether a date belongs to the previous month without needing to filter directly by year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If this post&amp;nbsp;helps, then please consider&amp;nbsp;Accepting it as the solution&amp;nbsp;to help the other members find it more quickly.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In case there is still a problem, please feel free and explain your issue in detail,&amp;nbsp;It will be my pleasure to assist you in any way I can.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 14:30:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670535#M142368</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-01-31T14:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: If Statements for last week in Direct Query grabbing all years</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670568#M142376</link>
      <description>&lt;P&gt;&lt;SPAN&gt;When I entered it into DAX, it says that there are too many arguments passed in this section:&lt;BR /&gt;||&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;AND (&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MONTH ( DimDate[Date] ) = 12,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MONTH ( TODAY() ) = 1,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;YEAR ( DimDate[Date] ) = YEAR ( TODAY() ) - 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 14:46:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/If-Statements-for-last-week-in-Direct-Query-grabbing-all-years/m-p/3670568#M142376</guid>
      <dc:creator>PhazeRCIL</dc:creator>
      <dc:date>2024-01-31T14:46:22Z</dc:date>
    </item>
  </channel>
</rss>

