<?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: To **bleep** With NEXTDAY (Lone Biker of the Apocalypse) in Quick Measures Gallery</title>
    <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-NEXTDAY-Lone-Biker-of-the-Apocalypse/m-p/1834634#M698</link>
    <description>&lt;P&gt;Does explain why I get blank on previousday using a date table? Using&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;{ TODAY() - 1 } works like a charm.&amp;nbsp; So annoying. To hell with with previousday function!&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 11 May 2021 00:05:10 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-05-11T00:05:10Z</dc:date>
    <item>
      <title>To **bleep** With NEXTDAY (Lone Biker of the Apocalypse)</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-NEXTDAY-Lone-Biker-of-the-Apocalypse/m-p/1245497#M574</link>
      <description>&lt;P&gt;&lt;FONT size="5"&gt;&lt;EM&gt;"Last night I had a dream. I drifted off thinking about happiness, birth and new life. But now I was haunted by a vision of DAX time intelligence functions. They...were...horrible..."&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;So, similar to how I&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.powerbi.com/t5/Community-Blog/Excel-to-DAX-Translation/ba-p/1060991" target="_self"&gt;recreated all of those Excel functions&lt;/A&gt;, my next fun project is unwiding the insanity that are the DAX Time Intelligence Functions. Sure,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008" target="_self"&gt;I started that a long time ago&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;but might as well get specific. BTW, this all started with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.powerbi.com/t5/Quick-Measures-Gallery/To-bleep-With-STARTOFQUARTER/td-p/1240067" target="_self"&gt;To **bleep** With STARTOFQUARTER&lt;/A&gt;. Here I cover NEXTDAY, PREVIOUSDAY, NEXTMONTH, PREVIOUSMONTH, NEXTQUARTER, PREVIOUSQUARTER, NEXTYEAR, PREVIOUSYEAR&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ToHellWithNEXTDAY = ( MAX('Data'[Date]) + 1)

ToHellWithPREVIOUSDAY = MAX('Data'[Date]) - 1&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fail 1 is when you might, quite naturally, think that you should feed the date you are trying to find the start of the month for in as a parameter. Fail.&lt;/P&gt;
&lt;P&gt;Fail 2 is when you pass in the parameter of a date column in a date table but you don't have a relationship with that particular date table that is in context. Fail.&lt;/P&gt;
&lt;P&gt;When it actually works, you have to have a relationship with your date table in context AND pass in the parameter of a date column in that date table. Oh, except that nice blank row that you get... Fail.&lt;/P&gt;
&lt;P&gt;Turns out, in order to get NEXTDAY, and most other time intelligence functions, to work you must adhere to the following strict guidelines:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a date table with all possible dates for which you might want to find the next day&lt;/LI&gt;
&lt;LI&gt;Use said date table as the parameter for the NEXTDAY function&lt;/LI&gt;
&lt;LI&gt;Ensure that a relationship exists between your fact table and your date table&lt;/LI&gt;
&lt;LI&gt;Ensure that the cardinality of the relationship is such that it is Single from your fact table to your date table&lt;/LI&gt;
&lt;LI&gt;Stand on your head and spin around 3 times while clicking your heels together and singing "&lt;EM&gt;I'm Too Sexy&lt;/EM&gt;" by Right Said Fred&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;And somehow this is better than just + 1 or - 1?&lt;/P&gt;
&lt;P&gt;But perhaps the biggest problem with all of these functions is:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;This function is not supported for use in DirectQuery mode when used in calculated columns or row-level security (RLS) rules.&lt;/STRONG&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Anyway, here are the table forms of all of these functions. Just replace TODAY() with whatever date you want. And all of these will work in DirectQuery mode and with RLS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;ToHellWithNEXTDAY = { TODAY() + 1 }


ToHellWithPREVIOUSDAY = { TODAY() - 1 }


ToHellWithNEXTMONTH = 
    VAR __Date = TODAY()
    VAR __NextMonth = EOMONTH(__Date,1)
    VAR __Month = MONTH(__NextMonth)
    VAR __Year = YEAR(__NextMonth)
RETURN
    CALENDAR(DATE(__Year,__Month,1),__NextMonth)


ToHellWithPREVIOUSMONTH = 
    VAR __Date = TODAY()
    VAR __NextMonth = EOMONTH(__Date,-1)
    VAR __Month = MONTH(__NextMonth)
    VAR __Year = YEAR(__NextMonth)
RETURN
    CALENDAR(DATE(__Year,__Month,1),__NextMonth)


ToHellWithNEXTQUARTER = 
    VAR __Date = TODAY()
    VAR __Quarter = QUARTER(__Date)
    VAR __Year = SWITCH(__Quarter,4,YEAR(__Date) + 1,YEAR(__Date))
    VAR __MonthStart = SWITCH(__Quarter,1,4,2,7,3,10,1)
    VAR __MonthEnd = SWITCH(__Quarter,1,6,2,9,3,12,3)
    VAR __Day = SWITCH(__Quarter,1,30,2,30,3,31,31)
RETURN
    CALENDAR(DATE(__Year,__MonthStart,1),DATE(__Year,__MonthEnd,__Day))


ToHellWithPREVIOUSQUARTER = 
    VAR __Date = TODAY()
    VAR __Quarter = QUARTER(__Date)
    VAR __Year = SWITCH(__Quarter,1,YEAR(__Date) - 1,YEAR(__Date))
    VAR __MonthStart = SWITCH(__Quarter,1,10,2,1,3,4,7)
    VAR __MonthEnd = SWITCH(__Quarter,1,12,2,3,3,6,9)
    VAR __Day = SWITCH(__Quarter,1,31,2,31,3,30,30)
RETURN
    CALENDAR(DATE(__Year,__MonthStart,1),DATE(__Year,__MonthEnd,__Day))


ToHellWithNEXTYEAR = 
    VAR __Date = TODAY()
    VAR __Year = YEAR(__Date) + 1
RETURN
    CALENDAR(DATE(__Year,1,1),DATE(__Year,12,31))


ToHellWithPREVIOUSYEAR = 
    VAR __Date = TODAY()
    VAR __Year = YEAR(__Date) - 1
RETURN
    CALENDAR(DATE(__Year,1,1),DATE(__Year,12,31))
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sure, these use CALENDAR but if you want to filter a calendar table, knock yourself out, you can do that too.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="reportid hidden"&gt;eyJrIjoiNDJlMWI2OTYtY2Y5MC00OGZiLTllMjQtNjdlZjMyODQ1YTU5IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 21:16:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-NEXTDAY-Lone-Biker-of-the-Apocalypse/m-p/1245497#M574</guid>
      <dc:creator>Greg_Deckler</dc:creator>
      <dc:date>2020-07-24T21:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: To **bleep** With NEXTDAY (Lone Biker of the Apocalypse)</title>
      <link>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-NEXTDAY-Lone-Biker-of-the-Apocalypse/m-p/1834634#M698</link>
      <description>&lt;P&gt;Does explain why I get blank on previousday using a date table? Using&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;{ TODAY() - 1 } works like a charm.&amp;nbsp; So annoying. To hell with with previousday function!&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 11 May 2021 00:05:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/To-bleep-With-NEXTDAY-Lone-Biker-of-the-Apocalypse/m-p/1834634#M698</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-05-11T00:05:10Z</dc:date>
    </item>
  </channel>
</rss>

