<?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: Filtering last day with data in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730803#M35825</link>
    <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt; , Try like this. Not sure if _monday logic is working &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;last_day_with_data = &lt;BR /&gt;var _max = maxx(allselected('Table'), 'Table'[date])&lt;BR /&gt;var _min = maxx(filter('Table', 'Table'[Date] &amp;lt;_max), 'Table'[Date])&lt;BR /&gt;var _min2 = maxx(filter('Table', 'Table'[Date] &amp;lt;_min), 'Table'[Date]) //use _min2 and _min if needed &lt;BR /&gt;return &lt;BR /&gt;VAR _yesterday = CALCULATE(&lt;BR /&gt;SUM('Table'[value]), &lt;BR /&gt;FILTER ('Table', &lt;BR /&gt;DATEVALUE ('Table'[Date]) = _max ))&lt;BR /&gt;VAR _daybefore = CALCULATE(&lt;BR /&gt;SUM('Table'[value]), &lt;BR /&gt;FILTER ('Table', &lt;BR /&gt;DATEVALUE ('Table'[Date]) = _min))&lt;BR /&gt;VAR _monday = [weekday_measure] = "maanantai"&lt;BR /&gt;RETURN&lt;BR /&gt;IF(_monday, _daybefore, _yesterday)&lt;/P&gt;</description>
    <pubDate>Thu, 18 Mar 2021 14:41:51 GMT</pubDate>
    <dc:creator>amitchandak</dc:creator>
    <dc:date>2021-03-18T14:41:51Z</dc:date>
    <item>
      <title>Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730784#M35822</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to build a measure that shows the data either from yesterday or the day before depending on the day of the week. Since there are no new data uploads on Sunday, I want to show the data from Saturday on Mondays. No matter what I do the measure is showing blank on Mondays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how my measure looks like:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;last_day_with_data = 
VAR _yesterday = CALCULATE(
    SUM('Table'[value]), 
    FILTER ('Table', 
    DATEVALUE ('Table'[timestamp]) = DATEVALUE(MAX('Table'[timestamp])-1)))
VAR _daybefore = CALCULATE(
    SUM('Table'[value]), 
    FILTER ('Table', 
    DATEVALUE ('Table'[timestamp]) = DATEVALUE(MAX('Table'[timestamp])-2)))
VAR _monday = [weekday_measure] = "maanantai"
RETURN
IF(_monday, _daybefore, _yesterday)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with this? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; You can find the pbix in &lt;A href="https://drive.google.com/file/d/1VHx5bOXvxCgOErvF9P3W5vHoaTNqgoJL/view?usp=sharing" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jules&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 14:30:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730784#M35822</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-18T14:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730803#M35825</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt; , Try like this. Not sure if _monday logic is working &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;last_day_with_data = &lt;BR /&gt;var _max = maxx(allselected('Table'), 'Table'[date])&lt;BR /&gt;var _min = maxx(filter('Table', 'Table'[Date] &amp;lt;_max), 'Table'[Date])&lt;BR /&gt;var _min2 = maxx(filter('Table', 'Table'[Date] &amp;lt;_min), 'Table'[Date]) //use _min2 and _min if needed &lt;BR /&gt;return &lt;BR /&gt;VAR _yesterday = CALCULATE(&lt;BR /&gt;SUM('Table'[value]), &lt;BR /&gt;FILTER ('Table', &lt;BR /&gt;DATEVALUE ('Table'[Date]) = _max ))&lt;BR /&gt;VAR _daybefore = CALCULATE(&lt;BR /&gt;SUM('Table'[value]), &lt;BR /&gt;FILTER ('Table', &lt;BR /&gt;DATEVALUE ('Table'[Date]) = _min))&lt;BR /&gt;VAR _monday = [weekday_measure] = "maanantai"&lt;BR /&gt;RETURN&lt;BR /&gt;IF(_monday, _daybefore, _yesterday)&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 14:41:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730803#M35825</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2021-03-18T14:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730854#M35838</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="148838" data-lia-user-login="amitchandak" class="lia-mention lia-mention-user"&gt;amitchandak&lt;/a&gt;.&amp;nbsp;I expressed myself poorly. I need to show data from yesterday (on every other day than Monday) or the day before (on Mondays) even though there would be data from the ongoing day also. Your solution is showing data from today.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Julia&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 15:01:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730854#M35838</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-18T15:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730936#M35844</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For such calculations (and for many, many more reasons) you should have a Date table in your model. Cramping everything into one table is a sure way to fail miserably without even knowing when and where. Please refer to &lt;A href="https://docs.microsoft.com/en-us/power-bi/guidance/star-schema" target="_self"&gt;this article&lt;/A&gt; to know what a good model suitable for PBI should look like.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a solution for the times when your model is correct:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[Last Day With Data] =
// Your 'Dates' table has to have
// fields like ShortDayName (Mon, Tue,...),
// LongDayName (Monday, Tuesday),
// WeekDayNumber (Monday = 1, Tuesday = 2,...)
// and more... It should also be marked as a Date
// table in the model.
var CurrentDay =
    SELECTEDVALUE( 'Dates'[Date] )
var IsMonday =
    SELECTEDVALUE( 'Dates'[WeekDayNumber] ) = 1
var LastDayWithData = CurrentDay - 1 - int( IsMonday )
var Result =
    CALCULATE(
        [Your Base Measure],
        'Dates'[Date] = LastDayWithData
    )
RETURN
    Result&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 18 Mar 2021 15:47:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1730936#M35844</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-18T15:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1731012#M35850</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your suggestion. You're right about the date table. I should really start using it every time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There's still something wrong with the measure because it is returning blank. If you have time and energy I would really appreciate if you could take a look at the &lt;A href="https://drive.google.com/file/d/1fbGnNR7rFtMAYk5GxIQns1Uaz5OCiXEa/view?usp=sharing" target="_self"&gt;pbix&lt;/A&gt; file. Your measure can be found with the name&amp;nbsp;&lt;EM&gt;last_day_with_data3&lt;/EM&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;last_day_with_data3 = 
var _CurrentDay = SELECTEDVALUE( 'Dates'[Date] ) 
var _IsMonday = SELECTEDVALUE( 'Dates'[DayOfWeekNumber] ) = 1 
var _LastDayWithData = _CurrentDay - 1 - int( _IsMonday ) 
var _Result = CALCULATE(
    SUM('Table'[value]), Dates[Date] = _LastDayWithData)
RETURN 
_Result &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 16:15:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1731012#M35850</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-18T16:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1731135#M35855</link>
      <description>&lt;P&gt;Can't for the time being open the file (I'm at work). This measure will return a value only in case a single date is visible in the current context since you have not defined what to return if there are more dates visible. And, obviously, your Dates must be related to your fact table...&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 17:20:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1731135#M35855</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-18T17:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1732431#M35916</link>
      <description>&lt;P&gt;The tables are related and I'm using a slicer to filter a single date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some other changes are needed...&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 09:30:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1732431#M35916</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-19T09:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1732604#M35924</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The measure is correct. Something on your side is not. For this to work, you have to hide your fact table and only slice by dimensions (you should almost never slice by anything that's in your fact tables). Mark your Dates table as the Date table in the model.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 10:47:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1732604#M35924</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-03-19T10:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1732624#M35925</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course you can't see anything because to see anything you have to filter ONE DATE ONLY. You don't filter for one date in your file. You have a bunch of them selected in the slicer. It's even worse. You are using a column from your fact table as the column for a slicer. This will never work correcttly. As mentioned above: slicing is always done through dimensions, fact tables are always hidden.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 10:58:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1732624#M35925</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2021-03-19T10:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering last day with data</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1732657#M35926</link>
      <description>&lt;P&gt;Try to start with this:&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/learn/powerplatform/power-bi" target="_blank"&gt;Power BI on Microsoft Learn | Microsoft Docs&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 11:06:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-last-day-with-data/m-p/1732657#M35926</guid>
      <dc:creator>daxer-almighty</dc:creator>
      <dc:date>2021-03-19T11:06:53Z</dc:date>
    </item>
  </channel>
</rss>

