<?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: Dax query that calculate InWork hours excluding weakeneds in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237282#M167601</link>
    <description>&lt;P&gt;No unfortunately&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2024 15:42:29 GMT</pubDate>
    <dc:creator>nony97</dc:creator>
    <dc:date>2024-10-10T15:42:29Z</dc:date>
    <item>
      <title>Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237002#M167588</link>
      <description>&lt;P&gt;i wrote the following dax query that calculate work hourse 8am to 5 pm however i need it to exclude the weekend (exclude saturday and friyday) please help&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example this is how it currenlty is being calculatined&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;start date&lt;/TD&gt;&lt;TD&gt;end date&lt;/TD&gt;&lt;TD&gt;work hourse&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4/22/2022 3:00&lt;/TD&gt;&lt;TD&gt;4/23/2022 14:04:00&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;this is how i want it to be&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;start date&lt;/TD&gt;&lt;TD&gt;end date&lt;/TD&gt;&lt;TD&gt;work hourse&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4/22/2022 3:00&lt;/TD&gt;&lt;TD&gt;4/23/2022 14:04:00&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and here is the query&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;workhours new = 
-- Working Start and End time 
VAR WorkTimeStart = TIME ( 08, 00, 00 )
VAR WorkTimeEnd = TIME ( 17, 10, 10 )
VAR WorkingHours = ( WorkTimeEnd - WorkTimeStart )

-- Start and End date/time on current row
VAR StartingDateTime = [start date]
VAR EndingDateTime   = [end date]

VAR StartingTime= StartingDateTime - TRUNC ( StartingDateTime )
VAR StartingDate = StartingDateTime - StartingTime

VAR EndingTime = EndingDateTime - TRUNC ( EndingDateTime )
VAR EndingDate = EndingDateTime - EndingTime

-- Adjust start/end times to fall within working hours.
VAR StartingTimeEffective =
    MIN (
        MAX ( StartingTime, WorkTimeStart ),
        WorkTimeEnd
    )
VAR EndingTimeEffective =
    MAX (
        MIN ( EndingTime, WorkTimeEnd ),
        WorkTimeStart
    )
-- Adjust for hours not worked on StartingDate
--   StartingTimeOffset will always be &amp;lt;= 0
VAR StartingTimeOffset =
    WorkTimeStart - StartingTimeEffective
-- Adjust for hours not worked on EndingDate
--   EndingTimeOffset will always be &amp;lt;= 0
VAR EndingTimeOffset =
    EndingTimeEffective - WorkTimeEnd
VAR DayCount =
    EndingDate - StartingDate + 1
VAR TotalTimeInDays =
    DayCount * WorkingHours + StartingTimeOffset + EndingTimeOffset
VAR TotalTimeInHours =
    TotalTimeInDays * 24

RETURN
    TotalTimeInHours&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2024 12:37:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237002#M167588</guid>
      <dc:creator>nony97</dc:creator>
      <dc:date>2024-10-10T12:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237278#M167600</link>
      <description>&lt;P&gt;Do you have a seperate date table that defines the weekends ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 15:41:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237278#M167600</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-10-10T15:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237282#M167601</link>
      <description>&lt;P&gt;No unfortunately&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 15:42:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237282#M167601</guid>
      <dc:creator>nony97</dc:creator>
      <dc:date>2024-10-10T15:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237293#M167602</link>
      <description>&lt;P&gt;I think its better that you create one.It would make a lot of things much simpler.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;DimDate = 
ADDCOLUMNS(
    CALENDAR(DATE(2020, 1, 1), DATE(2030, 12, 31)),   -- Define the date range
    "Year", YEAR([Date]),                              -- Year
    "Month Number", MONTH([Date]),                     -- Month Number (1 to 12)
    "Month Name", FORMAT([Date], "MMMM"),              -- Full Month Name (January, February, etc.)
    "Day", DAY([Date]),                                -- Day of the month
    "Weekday Number", WEEKDAY([Date], 2),              -- Weekday Number (1 = Monday, 7 = Sunday)
    "Weekday Name", FORMAT([Date], "dddd"),            -- Full Weekday Name (Monday, Tuesday, etc.)
    "IsWeekend", IF(WEEKDAY([Date], 2) &amp;gt;= 6, TRUE(), FALSE()), -- Weekend (True/False)
    "Quarter", QUARTER([Date]),                        -- Quarter (1 to 4)
    "Quarter Name", "Q" &amp;amp; QUARTER([Date]),             -- Quarter Name (Q1, Q2, etc.)
    "Year-Quarter", YEAR([Date]) &amp;amp; "-Q" &amp;amp; QUARTER([Date]), -- Year and Quarter (2020-Q1, etc.)
    "Week Number", WEEKNUM([Date], 2),                 -- Week Number of the year
    "Year-Month", FORMAT([Date], "YYYY-MM"),           -- Year and Month (2020-01, etc.)
    "IsLeapYear", IF(MOD(YEAR([Date]), 4) = 0 &amp;amp;&amp;amp; (MOD(YEAR([Date]), 100) &amp;lt;&amp;gt; 0 || MOD(YEAR([Date]), 400) = 0), TRUE(), FALSE()) -- Is it a Leap Year?
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 10 Oct 2024 15:46:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237293#M167602</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-10-10T15:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237366#M167606</link>
      <description>&lt;P&gt;What is the next step after creating it?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 16:36:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237366#M167606</guid>
      <dc:creator>nony97</dc:creator>
      <dc:date>2024-10-10T16:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237372#M167607</link>
      <description>&lt;P&gt;Ignore the data in your calculation that are marked as weekends in the date table.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 16:52:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237372#M167607</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-10-10T16:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237373#M167608</link>
      <description>&lt;P&gt;But what if the&amp;nbsp;&lt;/P&gt;&lt;P&gt;request came on Saturday at 5 and ended on Sunday, it will calculate the workhours in Saturday which is not what i want&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 16:52:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237373#M167608</guid>
      <dc:creator>nony97</dc:creator>
      <dc:date>2024-10-10T16:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237375#M167609</link>
      <description>&lt;P&gt;If saturday is marked as weekend in your date table then your calculation should ignore it.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 16:54:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4237375#M167609</guid>
      <dc:creator>SachinNandanwar</dc:creator>
      <dc:date>2024-10-10T16:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4238222#M167661</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="821213" data-lia-user-login="nony97" class="lia-mention lia-mention-user"&gt;nony97&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I create a table as you mentioned.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Then I think you can use this DAX code.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;WorkHours =
VAR StartDate = [StartDate]
VAR EndDate = [EndDate]
VAR WorkingHoursPerDay = 9
VAR StartTime =
    TIME ( 8, 0, 0 )
VAR EndTime =
    TIME ( 17, 0, 0 )
VAR TotalDays =
    DATEDIFF ( StartDate, EndDate, DAY )
VAR Weekdays =
    FILTER (
        GENERATE (
            CALENDAR ( StartDate, EndDate ),
            VAR CurrentDay = [Date]
            RETURN
                ROW (
                    "Day", CurrentDay,
                    "IsWeekday", IF ( WEEKDAY ( CurrentDay, 2 ) IN { 5, 6 }, FALSE, TRUE )
                )
        ),
        [IsWeekday] = TRUE
    )
VAR TotalWeekdays =
    COUNTROWS ( Weekdays )
VAR TotalWorkHours =
    IF (
        TotalDays = 0,
        IF (
            WEEKDAY ( StartDate, 2 )
                IN { 5, 6 }
                    || WEEKDAY ( EndDate, 2 ) IN { 5, 6 },
            0,
            DATEDIFF ( StartDate, EndDate, HOUR )
        ),
        TotalWeekdays * WorkingHoursPerDay
    )
RETURN
    IF ( ISBLANK ( TotalWorkHours ), 0, TotalWorkHours )&lt;/LI-CODE&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;
&lt;P&gt;&lt;SPAN&gt;Best Regards&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yilong Zhou&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;helps&lt;/I&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;Accept it as the solution&lt;/I&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 06:09:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4238222#M167661</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-10-11T06:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dax query that calculate InWork hours excluding weakeneds</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4255427#M168573</link>
      <description>&lt;P&gt;thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;but the calculation is not 100% accurate can you plwasw help&amp;nbsp;&lt;/P&gt;&lt;P&gt;for wxample&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;start&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;ebd&lt;/TD&gt;&lt;TD&gt;cuurent result (Hours)&lt;/TD&gt;&lt;TD&gt;Desired result(Hours)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;04/06/2024&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;04/06/2024&lt;/TD&gt;&lt;TD&gt;2.00&lt;/TD&gt;&lt;TD&gt;1.19&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 24 Oct 2024 04:07:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Dax-query-that-calculate-InWork-hours-excluding-weakeneds/m-p/4255427#M168573</guid>
      <dc:creator>nony97</dc:creator>
      <dc:date>2024-10-24T04:07:02Z</dc:date>
    </item>
  </channel>
</rss>

