<?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: Assign patient to office based on most recent office visited. Struggling with measure. in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2538148#M71406</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="370271" data-lia-user-login="pharmboyrx" class="lia-mention lia-mention-user"&gt;pharmboyrx&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try the following methods. I have simulated some data that I hope will fit your situation. I understand that you want to count the number of people who have been seen more than once in the past year in the same office.&lt;/P&gt;
&lt;P&gt;Measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Count PatientID =
CALCULATE (
    COUNT ( 'fact-EncountersEBO8'[PatientID] ),
    FILTER (
        ALL ( 'fact-EncountersEBO8' ),
        [AppointmentFacilityName] = SELECTEDVALUE ( 'dim-Offices'[OfficeEnc] )
            &amp;amp;&amp;amp; [PatientID] = SELECTEDVALUE ( 'fact-EncountersEBO8'[PatientID] )
            &amp;amp;&amp;amp; [AppointmentDate]
                &amp;gt; MAX ( 'dim-Date1'[Dates] ) - 365
            &amp;amp;&amp;amp; [AppointmentDate] &amp;lt;= MAX ( 'dim-Date1'[Dates] )
    )
)
&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;More than once =
CALCULATE (
    DISTINCTCOUNT ( 'fact-EncountersEBO8'[PatientID] ),
    FILTER (
        ALLSELECTED ( 'fact-EncountersEBO8'[PatientID] ),
        [Count PatientID] &amp;gt;= 2
    )
)
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Please check the attached data, does it match the output you expect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Community Support Team _Charlotte&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
    <pubDate>Wed, 25 May 2022 07:52:16 GMT</pubDate>
    <dc:creator>v-zhangti</dc:creator>
    <dc:date>2022-05-25T07:52:16Z</dc:date>
    <item>
      <title>Assign patient to office based on most recent office visited. Struggling with measure.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2531581#M71032</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I work for a medical practice with multiple offices. Sometimes a patient will transfer their care from one office to another. I want to be able to count the people in care at an office (1 visit in the last year), but only if that is the office they most recently received care from. Right now the measure is counting patients who received care from an office in the past year even if the most recent visit was at a different office.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;fact-EncountersEBO8 is a table with all patient encounters. dim-Date1 is the date table. dim-Offices is the office table. I've used SELECTEDVALUE in the second table because the&amp;nbsp;&lt;SPAN&gt;'dim-Offices'[OfficeEnc] is in the slicer on the report and I want to use the slicer to control the measure output.&lt;BR /&gt;&lt;BR /&gt;Any help would be appreciated. I'm stumped.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;PtCountLastOffice = &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;_LastVisitperPatient&lt;/SPAN&gt;&lt;SPAN&gt; =&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;CALCULATETABLE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;   ADDCOLUMNS&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;      VALUES&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'fact-EncountersEBO8'[PatientID]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;      "@LatestDate"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'fact-EncountersEBO8'[AppointmentDate]&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;    ),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;   FILTER&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'dim-Date1'&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;      'dim-Date1'[Dates]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'dim-Date1'[Dates]&lt;/SPAN&gt;&lt;SPAN&gt;) - &lt;/SPAN&gt;&lt;SPAN&gt;365&lt;/SPAN&gt;&lt;SPAN&gt; &amp;amp;&amp;amp;+&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;      'dim-Date1'[Dates]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt;= &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'dim-Date1'[Dates]&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;   )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;_LastOfficeVisit&lt;/SPAN&gt;&lt;SPAN&gt; =&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;CALCULATETABLE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;   VALUES&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'fact-EncountersEBO8'[PatientID]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;   'fact-EncountersEBO8'[AppointmentFacilityName]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;SELECTEDVALUE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'dim-Offices'[OfficeEnc]&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;   FILTER&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;ALL&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'dim-Date1'&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;      'dim-Date1'[Dates]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'dim-Date1'[Dates]&lt;/SPAN&gt;&lt;SPAN&gt;) - &lt;/SPAN&gt;&lt;SPAN&gt;365&lt;/SPAN&gt;&lt;SPAN&gt; &amp;amp;&amp;amp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;      'dim-Date1'[Dates]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;lt;= &lt;/SPAN&gt;&lt;SPAN&gt;MAX&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'dim-Date1'[Dates]&lt;/SPAN&gt;&lt;SPAN&gt;)),&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;   TREATAS&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;_LastVisitperPatient&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'fact-EncountersEBO8'[PatientID]&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;'fact-EncountersEBO8'[AppointmentDate]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;   )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;COUNTROWS&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;_LastOfficeVisit&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 22 May 2022 21:44:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2531581#M71032</guid>
      <dc:creator>pharmboyrx</dc:creator>
      <dc:date>2022-05-22T21:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Assign patient to office based on most recent office visited. Struggling with measure.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2531669#M71036</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="370271" data-lia-user-login="pharmboyrx" class="lia-mention lia-mention-user"&gt;pharmboyrx&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;If I understand you correctly, here is one way to do this.&lt;BR /&gt;Create a calculated column in your fact table to note the last visit per ID.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then create a measure that counts the rows per the selected value.&lt;BR /&gt;I will let you add the date filter to this - you can use something like Today()-365.&lt;/P&gt;
&lt;P&gt;Please see the code and pictures below.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Let me know if you have any questions.&lt;BR /&gt;&lt;BR /&gt;If this solves your issues, please mark it as the &lt;STRONG&gt;solution, &lt;/STRONG&gt;so that others can find it easily. &lt;STRONG&gt;Kudos &lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;are nice too.&lt;BR /&gt;Nathaniel&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Last visit = 
var _curPID = [PID]
var _curDate = [Date]
var _maxDate = CALCULATE(MAX('PatientVisit'[Date]),FILTER('PatientVisit','PatientVisit'[PID]=_curPID))
var _lastVisit = If(_maxDate=_curDate,'PatientVisit'[Office],"")
return _lastVisit
================================
Total Visits = 
var _OfficeSelected = AllSelected(TableOfc[Office])

return
CALCULATE(COUNTROWS(PatientVisit),FILTER(PatientVisit,PatientVisit[Last visit]= _OfficeSelected))&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 00:53:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2531669#M71036</guid>
      <dc:creator>Nathaniel_C</dc:creator>
      <dc:date>2022-05-23T00:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assign patient to office based on most recent office visited. Struggling with measure.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2538148#M71406</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="370271" data-lia-user-login="pharmboyrx" class="lia-mention lia-mention-user"&gt;pharmboyrx&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try the following methods. I have simulated some data that I hope will fit your situation. I understand that you want to count the number of people who have been seen more than once in the past year in the same office.&lt;/P&gt;
&lt;P&gt;Measure:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Count PatientID =
CALCULATE (
    COUNT ( 'fact-EncountersEBO8'[PatientID] ),
    FILTER (
        ALL ( 'fact-EncountersEBO8' ),
        [AppointmentFacilityName] = SELECTEDVALUE ( 'dim-Offices'[OfficeEnc] )
            &amp;amp;&amp;amp; [PatientID] = SELECTEDVALUE ( 'fact-EncountersEBO8'[PatientID] )
            &amp;amp;&amp;amp; [AppointmentDate]
                &amp;gt; MAX ( 'dim-Date1'[Dates] ) - 365
            &amp;amp;&amp;amp; [AppointmentDate] &amp;lt;= MAX ( 'dim-Date1'[Dates] )
    )
)
&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;More than once =
CALCULATE (
    DISTINCTCOUNT ( 'fact-EncountersEBO8'[PatientID] ),
    FILTER (
        ALLSELECTED ( 'fact-EncountersEBO8'[PatientID] ),
        [Count PatientID] &amp;gt;= 2
    )
)
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Please check the attached data, does it match the output you expect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Community Support Team _Charlotte&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;STRONG&gt;&lt;EM&gt;Accept it as the solution&lt;/EM&gt;&lt;/STRONG&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 07:52:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2538148#M71406</guid>
      <dc:creator>v-zhangti</dc:creator>
      <dc:date>2022-05-25T07:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assign patient to office based on most recent office visited. Struggling with measure.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2540183#M71532</link>
      <description>&lt;P&gt;Thanks for this, but what I'm really trying to do is count the number of patients in care at an office who have had 1 vist in the last 1 year. However, I only want them counted by the office they were most recently seen at.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if an patient was seen today at Office 3, but then seen 10/1/22 at Office 5, I would want them counted as part of Office 5's population in October, but in Office 3's population before that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I edited your file so that Patient 3 has visits in multiple offices. The problem I'm having is that they continue being counted in the previous office even though they've gone to a new office. In this case Patient 4 is counted in Office 3 starting in June 2022, but is still being counted in Office 5 as well. I want them to stop being counted in the old office when they go to a new office.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the assistance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://1drv.ms/u/s!Aofhsl_vDJFAhHUY3qydTULtqwr1?e=G9JEiE" target="_self"&gt;PBIX File&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 01:45:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Assign-patient-to-office-based-on-most-recent-office-visited/m-p/2540183#M71532</guid>
      <dc:creator>pharmboyrx</dc:creator>
      <dc:date>2022-05-26T01:45:20Z</dc:date>
    </item>
  </channel>
</rss>

