Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
sbenzaquen
Helper I
Helper I

Issue with adding dates / sumifs

Hi, I need some help to determine the number of days off per person/team on a monthly basis with the input data shown below. The key problem is that some absence requests may cover different months (See example below row 2). 

 

The way I initially approached this is by splitting the number of days-off impacting every month (columns H and K) in the input data to then use the excel logic of a sumif (in which I add both columns at any given month using columns I and K as criteria ranges). However, this does not work when using a Drax measure (sum(leg1 absence days)+sum(leg2 absence days)) and using either Leg1/leg2 month cut-off in the X-axis. Appreciate if you could please help as I'm relatively new to using PowerBI.

 

sbenzaquen_1-1615815829797.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sbenzaquen ,

 

1. Add columns to original table:

Hours in 1st Month =
VAR _sym =
    FORMAT ( 'Table'[Start Date], "YYYY-MM" )
VAR _eym =
    FORMAT ( 'Table'[End Date], "YYYY-MM" )
VAR _val =
    IF (
        _sym = _eym,
        [Days/Hours],
        DATEDIFF ( 'Table'[Start Date], ENDOFMONTH ( 'Table'[Start Date].[Date] ), DAY ) - 1
    )
RETURN
    IF ( [Start Date] = [End Date], _val, _val * 24 )
Hours in 2nd Month =
IF (
    [Start Date] = [End Date],
    [Days/Hours] - [Hours in 1st Month],
    [Days/Hours] * 24 - [Hours in 1st Month]
)

2.Create two calculated tables:

Fist table =
DISTINCT (
    SELECTCOLUMNS (
        'Table',
        "YearMonth", FORMAT ( 'Table'[Start Date], "YYYY-MM" ),
        "Member", [Team Member Name]
    )
)
Column =
CALCULATE (
    SUM ( 'Table'[Hours in 1st Month] ),
    FILTER (
        'Table',
        'Table'[Team Member Name] = [Member]
            && FORMAT ( 'Table'[Start Date], "YYYY-MM" ) = [YearMonth]
    )
)

......

3.The final output:

Final =
FILTER ( UNION ( 'Second Table', 'Fist table' ), [Column] <> 0 )

3.17.5.sep.PNG

Please take a look at the pbix file here

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @sbenzaquen ,

 

1. Add columns to original table:

Hours in 1st Month =
VAR _sym =
    FORMAT ( 'Table'[Start Date], "YYYY-MM" )
VAR _eym =
    FORMAT ( 'Table'[End Date], "YYYY-MM" )
VAR _val =
    IF (
        _sym = _eym,
        [Days/Hours],
        DATEDIFF ( 'Table'[Start Date], ENDOFMONTH ( 'Table'[Start Date].[Date] ), DAY ) - 1
    )
RETURN
    IF ( [Start Date] = [End Date], _val, _val * 24 )
Hours in 2nd Month =
IF (
    [Start Date] = [End Date],
    [Days/Hours] - [Hours in 1st Month],
    [Days/Hours] * 24 - [Hours in 1st Month]
)

2.Create two calculated tables:

Fist table =
DISTINCT (
    SELECTCOLUMNS (
        'Table',
        "YearMonth", FORMAT ( 'Table'[Start Date], "YYYY-MM" ),
        "Member", [Team Member Name]
    )
)
Column =
CALCULATE (
    SUM ( 'Table'[Hours in 1st Month] ),
    FILTER (
        'Table',
        'Table'[Team Member Name] = [Member]
            && FORMAT ( 'Table'[Start Date], "YYYY-MM" ) = [YearMonth]
    )
)

......

3.The final output:

Final =
FILTER ( UNION ( 'Second Table', 'Fist table' ), [Column] <> 0 )

3.17.5.sep.PNG

Please take a look at the pbix file here

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Eyelyn, thank you very much for providing such a great answer. It works perfectly. 

Kind regards,

Salvador

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.