<?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: Relation over 3 tables with a date in one and date span in another table in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3993104#M154993</link>
    <description>&lt;P&gt;Hello&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for your quick reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result screenshot you posted shows exactly what I am looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I have trouble understanding something:&lt;/P&gt;&lt;P&gt;1. &lt;STRIKE&gt;What is the purpose of the MAX() function do in this case?&lt;BR /&gt;&lt;/STRIKE&gt;&amp;nbsp; &amp;nbsp;I think I could answer this myself, it is because the filter returns a list (0..n rows), but we want exactly one row.&lt;/P&gt;&lt;P&gt;2. How does it know which employee to filter for? There seems to be no filter for the employee/person in your provided response? &lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Lars&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jun 2024 10:16:27 GMT</pubDate>
    <dc:creator>lars_hei</dc:creator>
    <dc:date>2024-06-14T10:16:27Z</dc:date>
    <item>
      <title>Relation over 3 tables with a date in one and date span in another table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3991624#M154867</link>
      <description>&lt;P&gt;Hey there!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For analysing our sales activity, we currently have the following setup:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Phone Calls       Employees          Employee Assignments
--------------------------------------------------------
person_id - - - - person_id
                  employee_id - - -  employee_id
                                     employee_function
                  current_team       employee_team
call date - - - - - - - - - + - - -  date_from
                            + - - -  date_until&lt;/LI-CODE&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;Please note that two tables share the&amp;nbsp;&lt;EM&gt;person_id&lt;/EM&gt; and two table share &lt;EM&gt;employee_id&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;If deemed helpful, adding a column with &lt;EM&gt;person_id&lt;/EM&gt; / &lt;EM&gt;employee_id&lt;/EM&gt; is not be a problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A report has already been created, but in the current report the employee assignments are missing.&lt;/P&gt;&lt;P&gt;Instead, the _current_ team and function are used,&lt;/P&gt;&lt;P&gt;which is not accurate if we go back a few months or want to have year-to-year comparisons.&lt;/P&gt;&lt;P&gt;(Employees changed teams -&amp;gt; wrong assignment; or even left the company -&amp;gt; no assignment)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What would we like to achieve?&lt;/P&gt;&lt;P&gt;We would like to always assign the correct role and team&lt;BR /&gt;of en employee&amp;nbsp;&lt;EM&gt;at the time of the phone call&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What was tried?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Relations&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;I was not sure how to set up relations between&lt;/P&gt;&lt;P&gt;a date and a daterange with separate date_from and date_until fields&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DAX&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;I am pretty new to the and tried some random stuff with DAX.&lt;/P&gt;&lt;P&gt;But none of that seemed to bring me forward.&lt;/P&gt;&lt;P&gt;I have read that you can relate data in DAX without having an actual relation in the model,&lt;/P&gt;&lt;P&gt;but I could not quite figure it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Extra column:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Probably the simplest approach is to add two columns to a phone call,&lt;/P&gt;&lt;P&gt;and just write&amp;nbsp;&lt;EM&gt;team&lt;/EM&gt; and&amp;nbsp;&lt;EM&gt;function&lt;/EM&gt; into those columns.&lt;/P&gt;&lt;P&gt;In SQL that would be something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;select 
  team, function
from 
  phone_calls pc
  join employees e on e.person_id = pc.person_id
  join employee_assginments ea.employee_id = e.employee_id
where
  ea.date_from &amp;lt;= pc.date 
  and (ea.date_until is null 
    or ea.date_until &amp;gt;= pc.date)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" color="#808080"&gt;SQL Query just added for clearer communication of what I would like to achieve &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I have no idea how to do this in PowerBI.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Can you give me a hint on what your recommended way of solving this would be?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H2&gt;Example Data&lt;/H2&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;name;person_id;employee_id
Anna;A;1
Bert;B;2
Carl;C;3
Dany;D;4

caller;call_date
A;2024-03-29
A;2024-03-25
A;2024-03-24
A;2024-03-23
A;2024-03-17
A;2024-03-14
A;2024-03-09
A;2024-03-03
A;2024-03-01
A;2024-02-24
A;2024-02-24
A;2024-02-21
A;2024-02-20
A;2024-02-18
A;2024-02-12
A;2024-02-08
A;2024-02-02
A;2024-01-28
A;2024-01-27
A;2024-01-21
A;2024-01-19
A;2024-01-12
A;2024-01-12
A;2024-01-07
A;2024-01-03
A;2024-01-02
A;2024-01-01
B;2024-04-12
B;2024-04-07
B;2024-04-03
B;2024-03-30
B;2024-03-27
B;2024-03-24
B;2024-03-20
B;2024-03-20
B;2024-03-18
B;2024-03-18
B;2024-03-18
B;2024-03-16
B;2024-03-11
B;2024-03-09
B;2024-03-07
B;2024-03-03
B;2024-02-29
B;2024-02-24
B;2024-02-24
B;2024-02-19
B;2024-02-16
B;2024-02-15
B;2024-02-12
B;2024-02-09
B;2024-02-04
B;2024-02-04
B;2024-02-04
B;2024-02-01
B;2024-01-31
B;2024-01-30
B;2024-01-25
B;2024-01-24
B;2024-01-24
B;2024-01-23
B;2024-01-23
B;2024-01-19
B;2024-01-14
B;2024-01-10
B;2024-01-05
B;2024-01-05
B;2024-01-01
C;2024-03-24
C;2024-03-18
C;2024-03-08
C;2024-03-04
C;2024-02-26
C;2024-02-26
C;2024-02-16
C;2024-02-07
C;2024-02-01
C;2024-01-30
C;2024-01-25
C;2024-01-18
C;2024-01-13
C;2024-01-12
C;2024-01-09
C;2024-01-01
D;2024-03-30
D;2024-03-29
D;2024-03-29
D;2024-03-26
D;2024-03-26
D;2024-03-24
D;2024-03-20
D;2024-03-17
D;2024-03-17
D;2024-03-12
D;2024-03-09
D;2024-03-04
D;2024-03-03
D;2024-02-28
D;2024-02-25
D;2024-02-23
D;2024-02-17
D;2024-02-14
D;2024-02-09
D;2024-02-04
D;2024-02-02
D;2024-01-30
D;2024-01-26
D;2024-01-23
D;2024-01-20
D;2024-01-17
D;2024-01-17
D;2024-01-17
D;2024-01-14
D;2024-01-09
D;2024-01-04
D;2024-01-02
D;2024-01-01

employee_id;employee_function;employee_team;date_from;date_until
1;lead;business;2020-01-01;
2;service;business;2022-01-01;2024-01-31
2;support;business;2024-02-01;
3;service;business;2023-01-01;2024-02-29
3;service;direct;2024-03-01;
4;support;business;2024-02-01;&lt;/LI-CODE&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>Thu, 13 Jun 2024 17:03:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3991624#M154867</guid>
      <dc:creator>lars_hei</dc:creator>
      <dc:date>2024-06-13T17:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Relation over 3 tables with a date in one and date span in another table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3992586#M154967</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="718616" data-lia-user-login="lars_hei" class="lia-mention lia-mention-user"&gt;lars_hei&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try to create a calculated column.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;EmployeeTeam = CALCULATE(
    MAX('table3'[employee_team]),
    FILTER(
        'table3',
        'table3'[date_from] &amp;lt;= 'table2'[call_date] &amp;amp;&amp;amp;
        (ISBLANK('table3'[date_until]) || 'table3'[date_until] &amp;gt;= 'table2'[call_date])
    )
)&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;EmployeeFunc = CALCULATE(
    MAX('table3'[employee_function]),
    FILTER(
        'table3',
        'table3'[date_from] &amp;lt;= 'table2'[call_date] &amp;amp;&amp;amp;
        (ISBLANK('table3'[date_until]) || 'table3'[date_until] &amp;gt;= 'table2'[call_date])
    )
)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is not the result you expect, please provide a screenshot or virtual table to help us better solve the problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Clara Gong&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 06:12:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3992586#M154967</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-14T06:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Relation over 3 tables with a date in one and date span in another table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3993104#M154993</link>
      <description>&lt;P&gt;Hello&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 quick reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result screenshot you posted shows exactly what I am looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I have trouble understanding something:&lt;/P&gt;&lt;P&gt;1. &lt;STRIKE&gt;What is the purpose of the MAX() function do in this case?&lt;BR /&gt;&lt;/STRIKE&gt;&amp;nbsp; &amp;nbsp;I think I could answer this myself, it is because the filter returns a list (0..n rows), but we want exactly one row.&lt;/P&gt;&lt;P&gt;2. How does it know which employee to filter for? There seems to be no filter for the employee/person in your provided response? &lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Lars&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jun 2024 10:16:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3993104#M154993</guid>
      <dc:creator>lars_hei</dc:creator>
      <dc:date>2024-06-14T10:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: Relation over 3 tables with a date in one and date span in another table</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3995559#M155194</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="718616" data-lia-user-login="lars_hei" class="lia-mention lia-mention-user"&gt;lars_hei&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;FILTER(
'table3',
'table3'[date_from] &amp;lt;= 'table2'[call_date] &amp;amp;&amp;amp;
(ISBLANK('table3'[date_until]) || 'table3'[date_until] &amp;gt;= 'table2'[call_date])
)&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;In this expression, table3 has been filtered according to the required conditions, and the filtered table is obtained, and then the required columns are taken out using the calculate function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second parameter of CALCULATE defines a Boolean expression or table expression for the filter or filter modifier function. Filters can be: Boolean filter expressions, table filter expressions, filter modification functions. Here, a table filter expression is used. A table expression filter applies a table object as a filter. It can be a reference to a model table, but it is more likely to be a function that returns a table object. You can use the FILTER function to apply complex filter conditions, including conditions that cannot be defined by a Boolean filter expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For more detailed information, please refer to the following links:&lt;BR /&gt;&lt;A href="https://learn.microsoft.com/en-us/dax/calculate-function-dax" target="_blank"&gt;CALCULATE function (DAX) - DAX | Microsoft Learn&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Community-Blog/The-CALCULATE-Function-In-Power-BI-DAX-Tutorial/ba-p/1944173" target="_blank"&gt;The CALCULATE Function In Power BI - DAX Tutorial - Microsoft Fabric Community&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Clara Gong&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2024 07:52:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Relation-over-3-tables-with-a-date-in-one-and-date-span-in/m-p/3995559#M155194</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-17T07:52:03Z</dc:date>
    </item>
  </channel>
</rss>

