<?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 Calculating the days per mont of a range date and aggregating it. in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-days-per-mont-of-a-range-date-and-aggregating-it/m-p/3361345#M126368</link>
    <description>&lt;P&gt;Good morning everyone.&lt;BR /&gt;&lt;BR /&gt;I am currently having a problem related to some dates. Right now I have a table that contain multiple columns:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Worker ID&lt;/LI&gt;&lt;LI&gt;Teams&lt;/LI&gt;&lt;LI&gt;First day of absence&lt;/LI&gt;&lt;LI&gt;Last day of absence&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;What I need is to distribute by Month the number of days it has been absent (in each month). I managed to do it with this code and using a basic date table:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Days of leave per month Numerador = 
VAR StartDayLeave = VALUE( SELECTEDVALUE( Leave_Active_2023[First_Day_of_Leave] ) )
VAR LastDayLeave = VALUE( SELECTEDVALUE( Leave_Active_2023[Last_Day_of_Leave_-_Actual] ) )
VAR MinDateInContext = VALUE( MIN( 'Dates'[Date] ) )
VAR MaxDateInContext = VALUE( MAX( 'Dates'[Date] ) )

Return
IF(AND( LastDayLeave &amp;gt; MinDateInContext, LastDayLeave &amp;lt; MaxDateInContext ),  MaxDateInContext  - LastDayLeave + 1,   
    IF( AND( StartDayLeave &amp;lt; MinDateInContext, LastDayLeave &amp;gt; MinDateInContext ) ,
        MaxDateInContext  - MinDateInContext + 1,
                IF( AND( AND( StartDayLeave &amp;gt; MinDateInContext, StartDayLeave &amp;lt; MaxDateInContext ), LastDayLeave &amp;gt; MinDateInContext ),
                     MIN( LastDayLeave, MaxDateInContext + 1 ) - StartDayLeave, 
                        BLANK() ) ))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This formula gives me the next table&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem comes when I try to aggregate the results by teams. I understand that the problem comes due to the MIN and MAX in the formula, seen that it takes the min value of the whole team, and the max value of the whole team. However, I cannot manage to find an answer. Does someone have any idea on how to solve this problem?&lt;BR /&gt;&lt;BR /&gt;Thank you very much!&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2023 08:36:16 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-08-02T08:36:16Z</dc:date>
    <item>
      <title>Calculating the days per mont of a range date and aggregating it.</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-days-per-mont-of-a-range-date-and-aggregating-it/m-p/3361345#M126368</link>
      <description>&lt;P&gt;Good morning everyone.&lt;BR /&gt;&lt;BR /&gt;I am currently having a problem related to some dates. Right now I have a table that contain multiple columns:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Worker ID&lt;/LI&gt;&lt;LI&gt;Teams&lt;/LI&gt;&lt;LI&gt;First day of absence&lt;/LI&gt;&lt;LI&gt;Last day of absence&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;What I need is to distribute by Month the number of days it has been absent (in each month). I managed to do it with this code and using a basic date table:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Days of leave per month Numerador = 
VAR StartDayLeave = VALUE( SELECTEDVALUE( Leave_Active_2023[First_Day_of_Leave] ) )
VAR LastDayLeave = VALUE( SELECTEDVALUE( Leave_Active_2023[Last_Day_of_Leave_-_Actual] ) )
VAR MinDateInContext = VALUE( MIN( 'Dates'[Date] ) )
VAR MaxDateInContext = VALUE( MAX( 'Dates'[Date] ) )

Return
IF(AND( LastDayLeave &amp;gt; MinDateInContext, LastDayLeave &amp;lt; MaxDateInContext ),  MaxDateInContext  - LastDayLeave + 1,   
    IF( AND( StartDayLeave &amp;lt; MinDateInContext, LastDayLeave &amp;gt; MinDateInContext ) ,
        MaxDateInContext  - MinDateInContext + 1,
                IF( AND( AND( StartDayLeave &amp;gt; MinDateInContext, StartDayLeave &amp;lt; MaxDateInContext ), LastDayLeave &amp;gt; MinDateInContext ),
                     MIN( LastDayLeave, MaxDateInContext + 1 ) - StartDayLeave, 
                        BLANK() ) ))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This formula gives me the next table&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem comes when I try to aggregate the results by teams. I understand that the problem comes due to the MIN and MAX in the formula, seen that it takes the min value of the whole team, and the max value of the whole team. However, I cannot manage to find an answer. Does someone have any idea on how to solve this problem?&lt;BR /&gt;&lt;BR /&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 08:36:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-days-per-mont-of-a-range-date-and-aggregating-it/m-p/3361345#M126368</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-02T08:36:16Z</dc:date>
    </item>
  </channel>
</rss>

