<?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: Looking for help with a complex DAX column tied to a standard relationship and change audits in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3394288#M128017</link>
    <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;HI&amp;nbsp;Anonymous&lt;/LI-USER&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;You can try to use the following calculated column formula(include the comment) to get the history dept based on condition:&lt;/FONT&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;HistDeptByCondition =
VAR _start =
    MINX ( Dept_Hist, [Date Changed] )
VAR _end =
    MAXX ( Dept_Hist, [Date Changed] )
RETURN
    IF (
        //records that out of the history table ranges
        Labor_Data[Actual Start] &amp;gt; _end,
        Labor_Data[User Department],
        IF (
            Labor_Data[Actual End] &amp;lt; _start,
            LOOKUPVALUE (
                Dept_Hist[From Department],
                Dept_Hist[USERKEY], Labor_Data[PERFORMEDBYKEY],
                Dept_Hist[Date Changed], _start
            ),
            //start date before or equal to change date and end date equal to department change date
            VAR endDateMatch =
                MAXX (
                    FILTER (
                        Dept_Hist,
                        Dept_Hist[Date Changed] &amp;gt;= Labor_Data[Actual Start]
                            &amp;amp;&amp;amp; DATEVALUE ( Labor_Data[Actual End] ) = DATEVALUE ( Dept_Hist[Date Changed] )
                    ),
                    [From Department]
                )
            RETURN
                IF (
                    endDateMatch &amp;lt;&amp;gt; BLANK (),
                    endDateMatch,
                    //if not end at the same day, find the next change records and use its 'from department' as history
                    MINX (
                        FILTER ( Dept_Hist, Dept_Hist[Date Changed] &amp;gt;= Labor_Data[Actual End] ),
                        [From Department]
                    )
                )
        )
    )&lt;/LI-CODE&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;img /&gt;&lt;/FONT&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Logic of dax formula conditions:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;1. Records that out of history table ranges.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;2. End date equal to the change date.&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;3. Records between two history records.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;BTW, I also attach the sample pbix file that used the second excel file as source, you can try it if helps.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Aug 2023 08:41:12 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-08-23T08:41:12Z</dc:date>
    <item>
      <title>Looking for help with a complex DAX column tied to a standard relationship and change audits</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3385582#M127574</link>
      <description>&lt;P&gt;Good day, Community!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hoping someone might be able to assist with a calculated DAX column I am struggling with. I will try to do my best to explain...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Table references as in the attached example data&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The column would start by pulling in a User's Department from a standard related table (User Table [USERKEY]) into a date related time fact table [Time_Data_Table] if until the user's department has been changed, which would be recorded in the [Department_Change_History] table. If changed, I would need to pull the&amp;nbsp;&lt;EM&gt;old&lt;/EM&gt; department [From Department] value for all of the historic time entries up until the date/time the change was made. This would be for each change that has taken place, as some users may have changed more than once.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;USERKEY 742's Department was changed from PBIHA to PBIM on 8/2/2023 22:37. In the time data table, I would need USERKEY 742's new "USER DEPARTMENT" column to read as PBIHA for any time entry prior to the change date/time. Any user without a change would simply be the department listed in the User_Table in this same column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, if a user had no changes associated in the audit table, the new User Department would simply be what is recorded in the User_Table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts and or help here is immensely appreciated!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example data:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://1drv.ms/x/s!ApRgo9x4tvOZqiFfF8Yg4p9AFMeF?e=o7KNNn" target="_blank"&gt;Example_Data.xlsx&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 14:45:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3385582#M127574</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-17T14:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help with a complex DAX column tied to a standard relationship and change audits</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3387702#M127671</link>
      <description>&lt;P&gt;So, it's the source data I am struggling with. I need to be able to get the From Department value for each time entry where the time entry date is before the date changed in the department change history. The issue I'm running into is when there are multiple changes per user in the change history...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;VAR Hist_Dept = 
    CALCULATE(
        SELECTEDVALUE(Department_Change_History[From Department]),
            FILTER(
                ALL(Department_Change_History),
                Department_Change_History[USERKEY] = Time_Data_Table[PERFORMEDBYKEY] &amp;amp;&amp;amp;
                Department_Change_History[Date Changed] &amp;gt;= Time_Data_Table[Actual Start]
            )
    )

RETURN
    IF(
        ISBLANK(Hist_Dept),
        RELATED(User_Table[User Department]),
        Hist_Dept
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 15:39:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3387702#M127671</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-18T15:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help with a complex DAX column tied to a standard relationship and change audits</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3391327#M127845</link>
      <description>&lt;P&gt;HI&amp;nbsp;Anonymous&lt;/LI-USER&gt;,&lt;/P&gt;
&lt;P&gt;Perhaps you can try to use the following expression to create a calculated column on 'Time_Data_Table' if it helps:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;USER DEPARTMENT =
VAR Hist_Dept =
    CALCULATE (
        MAX ( Department_Change_History[From Department] ),
        FILTER (
            Department_Change_History,
            [USERKEY] = Time_Data_Table[PERFORMEDBYKEY]
                &amp;amp;&amp;amp; AND (
                    [Date Changed] &amp;gt;= Time_Data_Table[Actual Start],
                    [Date Changed] &amp;lt;= Time_Data_Table[Actual End]
                )
        )
    )
RETURN
    IF (
        Hist_Dept = BLANK (),
        LOOKUPVALUE (
            User_Table[Department],
            User_Table[USERKEY], Time_Data_Table[PERFORMEDBYKEY]
        ),
        Hist_Dept
    )&lt;/LI-CODE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Xiaoxin Sheng&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 01:22:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3391327#M127845</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-22T01:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help with a complex DAX column tied to a standard relationship and change audits</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3393113#M127954</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;A href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/12837" target="_blank" rel="noopener"&gt;@v-shex-msft&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried a variation of that and what you provided, but that didn't seem to do the trick either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a new&amp;nbsp;&lt;A href="https://1drv.ms/x/s!ApRgo9x4tvOZqimpCC6stLMt_LpX?e=TwfyNG" target="_self" rel="nofollow noopener noreferrer"&gt;sample set of data here&lt;/A&gt;. The "Dept_Hist" tab contains the changes of a single user. The "Labor_Data" tab are all of the user's time punches. Column G ("Hist Department") shows the expected results. The other piece of the puzzle where a user has no change history is easy. It's just getting the from department based on the time stamps inbetween each change where multiple changes exist is the wall I keep running into.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help and insight here is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Aug 2023 17:32:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3393113#M127954</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-22T17:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help with a complex DAX column tied to a standard relationship and change audits</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3394288#M128017</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;HI&amp;nbsp;Anonymous&lt;/LI-USER&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;You can try to use the following calculated column formula(include the comment) to get the history dept based on condition:&lt;/FONT&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;HistDeptByCondition =
VAR _start =
    MINX ( Dept_Hist, [Date Changed] )
VAR _end =
    MAXX ( Dept_Hist, [Date Changed] )
RETURN
    IF (
        //records that out of the history table ranges
        Labor_Data[Actual Start] &amp;gt; _end,
        Labor_Data[User Department],
        IF (
            Labor_Data[Actual End] &amp;lt; _start,
            LOOKUPVALUE (
                Dept_Hist[From Department],
                Dept_Hist[USERKEY], Labor_Data[PERFORMEDBYKEY],
                Dept_Hist[Date Changed], _start
            ),
            //start date before or equal to change date and end date equal to department change date
            VAR endDateMatch =
                MAXX (
                    FILTER (
                        Dept_Hist,
                        Dept_Hist[Date Changed] &amp;gt;= Labor_Data[Actual Start]
                            &amp;amp;&amp;amp; DATEVALUE ( Labor_Data[Actual End] ) = DATEVALUE ( Dept_Hist[Date Changed] )
                    ),
                    [From Department]
                )
            RETURN
                IF (
                    endDateMatch &amp;lt;&amp;gt; BLANK (),
                    endDateMatch,
                    //if not end at the same day, find the next change records and use its 'from department' as history
                    MINX (
                        FILTER ( Dept_Hist, Dept_Hist[Date Changed] &amp;gt;= Labor_Data[Actual End] ),
                        [From Department]
                    )
                )
        )
    )&lt;/LI-CODE&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;img /&gt;&lt;/FONT&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Logic of dax formula conditions:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;1. Records that out of history table ranges.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;2. End date equal to the change date.&amp;nbsp;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;3. Records between two history records.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;BTW, I also attach the sample pbix file that used the second excel file as source, you can try it if helps.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 08:41:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3394288#M128017</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-23T08:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Looking for help with a complex DAX column tied to a standard relationship and change audits</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3395507#M128078</link>
      <description>&lt;P&gt;You're awesome! That looks like it works perfectly in the test model. The only issue I'm running into now is the complexity of the calculation. My actual model has a million plus rows and growing, so it seems to be too taxing of a formula (runs out of memory trying to calculate). I will keep churning to see if there is any way of possibly making it more efficient, but it may just be too much to handle either way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Aug 2023 19:30:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Looking-for-help-with-a-complex-DAX-column-tied-to-a-standard/m-p/3395507#M128078</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-23T19:30:12Z</dc:date>
    </item>
  </channel>
</rss>

