<?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 Dates in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3676787#M142772</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;To achieve this in DAX (Data Analysis Expressions), you can create a calculated column that flags the rows where LogInDate and LogOutDate occur on the same day and then identify the closest LogOutDate that occurs on the same day or after the LogInDate. Below is the DAX code to implement this logic:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PairFlag =&lt;BR /&gt;VAR CurrentUserId = 'YourTable'[User Id]&lt;BR /&gt;VAR CurrentLogInDate = 'YourTable'[LogInDate]&lt;BR /&gt;VAR SameDayLogOut =&lt;BR /&gt;FILTER(&lt;BR /&gt;'YourTable',&lt;BR /&gt;'YourTable'[User Id] = CurrentUserId &amp;amp;&amp;amp;&lt;BR /&gt;'YourTable'[LogOutDate] &amp;gt;= CurrentLogInDate &amp;amp;&amp;amp;&lt;BR /&gt;DATEDIFF('YourTable'[LogInDate], CurrentLogInDate, DAY) = 0&lt;BR /&gt;)&lt;BR /&gt;VAR ClosestLogOutDate =&lt;BR /&gt;MINX(&lt;BR /&gt;FILTER(&lt;BR /&gt;SameDayLogOut,&lt;BR /&gt;'YourTable'[LogOutDate] &amp;gt;= CurrentLogInDate&lt;BR /&gt;),&lt;BR /&gt;'YourTable'[LogOutDate]&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;IF(&lt;BR /&gt;'YourTable'[LogOutDate] = ClosestLogOutDate,&lt;BR /&gt;"x",&lt;BR /&gt;BLANK()&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;&lt;SPAN&gt;Replace 'YourTable' with the actual name of your table in your Power BI model. This DAX code creates a calculated column called PairFlag which checks for each row if there exists a LogOutDate on the same day as the LogInDate, and then finds the closest LogOutDate on the same day or after the LogInDate. If the LogOutDate is the closest one, it flags it with "x", otherwise, it remains blank.&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;&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Feb 2024 05:42:45 GMT</pubDate>
    <dc:creator>123abc</dc:creator>
    <dc:date>2024-02-03T05:42:45Z</dc:date>
    <item>
      <title>Filtering Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3676737#M142769</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;For each User ID,&amp;nbsp; I need to identify the rows where LogInDates occurs on the same day. After that I need to identify the closest LogOutDates that occurs on the same day or after. There can be only two dates in a pair but there can be multiple pairs for each UserId. The LogOutDate and is not dependant on the LoginDate. How do I do this in Dax?&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;User Id&lt;/TD&gt;&lt;TD&gt;LogInDate&lt;/TD&gt;&lt;TD&gt;LogOutDate&lt;/TD&gt;&lt;TD&gt;Expected&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;12/29/2013&lt;/TD&gt;&lt;TD&gt;1/1/2014&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;12/30/2014&lt;/TD&gt;&lt;TD&gt;1/1/2015&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;12/29/2014&lt;/TD&gt;&lt;TD&gt;1/1/2015&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;12/30/2014&lt;/TD&gt;&lt;TD&gt;1/1/2016&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1/30/2015&lt;/TD&gt;&lt;TD&gt;2/1/2015&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1/30/2015&lt;/TD&gt;&lt;TD&gt;2/1/2015&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1/30/2015&lt;/TD&gt;&lt;TD&gt;4/1/2015&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1/30/2015&lt;/TD&gt;&lt;TD&gt;3/1/2015&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;4/26/2016&lt;/TD&gt;&lt;TD&gt;5/1/2016&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5/27/2016&lt;/TD&gt;&lt;TD&gt;6/1/2016&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5/27/2016&lt;/TD&gt;&lt;TD&gt;6/1/2016&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5/28/2016&lt;/TD&gt;&lt;TD&gt;6/2/2016&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;5/29/2016&lt;/TD&gt;&lt;TD&gt;6/3/2016&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Feb 2024 04:39:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3676737#M142769</guid>
      <dc:creator>Barry_Sophus</dc:creator>
      <dc:date>2024-02-03T04:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3676787#M142772</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;To achieve this in DAX (Data Analysis Expressions), you can create a calculated column that flags the rows where LogInDate and LogOutDate occur on the same day and then identify the closest LogOutDate that occurs on the same day or after the LogInDate. Below is the DAX code to implement this logic:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PairFlag =&lt;BR /&gt;VAR CurrentUserId = 'YourTable'[User Id]&lt;BR /&gt;VAR CurrentLogInDate = 'YourTable'[LogInDate]&lt;BR /&gt;VAR SameDayLogOut =&lt;BR /&gt;FILTER(&lt;BR /&gt;'YourTable',&lt;BR /&gt;'YourTable'[User Id] = CurrentUserId &amp;amp;&amp;amp;&lt;BR /&gt;'YourTable'[LogOutDate] &amp;gt;= CurrentLogInDate &amp;amp;&amp;amp;&lt;BR /&gt;DATEDIFF('YourTable'[LogInDate], CurrentLogInDate, DAY) = 0&lt;BR /&gt;)&lt;BR /&gt;VAR ClosestLogOutDate =&lt;BR /&gt;MINX(&lt;BR /&gt;FILTER(&lt;BR /&gt;SameDayLogOut,&lt;BR /&gt;'YourTable'[LogOutDate] &amp;gt;= CurrentLogInDate&lt;BR /&gt;),&lt;BR /&gt;'YourTable'[LogOutDate]&lt;BR /&gt;)&lt;BR /&gt;RETURN&lt;BR /&gt;IF(&lt;BR /&gt;'YourTable'[LogOutDate] = ClosestLogOutDate,&lt;BR /&gt;"x",&lt;BR /&gt;BLANK()&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;&lt;SPAN&gt;Replace 'YourTable' with the actual name of your table in your Power BI model. This DAX code creates a calculated column called PairFlag which checks for each row if there exists a LogOutDate on the same day as the LogInDate, and then finds the closest LogOutDate on the same day or after the LogInDate. If the LogOutDate is the closest one, it flags it with "x", otherwise, it remains blank.&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;&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Feb 2024 05:42:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3676787#M142772</guid>
      <dc:creator>123abc</dc:creator>
      <dc:date>2024-02-03T05:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3676901#M142777</link>
      <description>&lt;P&gt;Simple enough&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Feb 2024 07:33:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3676901#M142777</guid>
      <dc:creator>ThxAlot</dc:creator>
      <dc:date>2024-02-03T07:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3683365#M143058</link>
      <description>&lt;P&gt;My appologies. I don't think what I explained was clear. What I am wanting is For each User ID, I want to determine if the LogoutDate is on/after the current row. If it is then flag those two rows then go to the next unflagged row and perform the same analysis.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 14:59:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Filtering-Dates/m-p/3683365#M143058</guid>
      <dc:creator>Barry_Sophus</dc:creator>
      <dc:date>2024-02-06T14:59:22Z</dc:date>
    </item>
  </channel>
</rss>

