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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
JC2022
Helper III
Helper III

Add days to date column (working days only)

Hi,

I have tableA with these columns:

JC2022_0-1690370681111.png

 

I also have a calendar table:

JC2022_1-1690370826321.png

 

In the WorkingDay column the weekends and holidays are "No" and the rest is "Yes". 

 

In a measure: I want to add the value (in days) in the Target Days column to the Date Created column. The dates with WorkingDay = "No" should not be counted as an added day.

 

For example: when Date Created = 26-07-2023 and Target Days = 15. 15 days later the date is 10-08-2023 but because there are 6 weekend days and 0 holidays between those 2 dates the correct date should be 16-08-2023. So basically the Target days are the working days that should be added. This should be done in a measure.

 

Can you help me?

4 REPLIES 4
Anonymous
Not applicable

Hi @JC2022 ,

You can create a calculated column as below to get it, please find the details in the attachment.

Target Date = 
VAR _tab =
    SUMMARIZE (
        FILTER (
            'calendar',
            'calendar'[WorkingDay] = "Yes"
                && 'calendar'[Date] > 'tableA'[Date Created]
        ),
        'calendar'[Date],
        'calendar'[WorkingDay],
        "@culcount",
            IF (
                'calendar'[WorkingDay] = "No",
                BLANK (),
                CALCULATE (
                    COUNT ( 'calendar'[Date] ),
                    FILTER (
                        ALLSELECTED ( 'calendar' ),
                        'calendar'[Date] <= EARLIER ( 'calendar'[Date] )
                    )
                )
            )
    )
RETURN
    MAXX ( FILTER ( _tab, [@culcount] <= 'tableA'[Target Days] ), [Date] )

vyiruanmsft_0-1690532752294.png

Best Regards

Hi @v-yiruan-msft,

Thanks for your response. I have tried your formula, but I can't choose my calendar table at the arrow in the picture below. The only table I can choose there is TableA. 

I am not sure but has this possibly something to do with TableA being a directquery table and Calendar being imported?

Thanks for your support!

 

JC2022_0-1690542462198.png

 

Anonymous
Not applicable

Hi @JC2022 ,

If the table 'TableA' from a Direct Query data source, there are some limitations here. 

vyiruanmsft_0-1690957201780.pngPlease try to create a measure as below to get it:

 

Target Date =
VAR _cdate =
    MAX ( 'tableA'[Date Created] )
VAR _tdays =
    MAX ( 'tableA'[Target Days] )
VAR _tab =
    SUMMARIZE (
        FILTER (
            'calendar',
            'calendar'[WorkingDay] = "Yes"
                && 'calendar'[Date] > _cdate
        ),
        'calendar'[Date],
        'calendar'[WorkingDay],
        "@culcount",
            IF (
                'calendar'[WorkingDay] = "No",
                BLANK (),
                CALCULATE (
                    COUNT ( 'calendar'[Date] ),
                    FILTER (
                        ALLSELECTED ( 'calendar' ),
                        'calendar'[Date] <= EARLIER ( 'calendar'[Date] )
                    )
                )
            )
    )
RETURN
    MAXX ( FILTER ( _tab, [@culcount] <= _tdays ), [Date] )

If the above one can't help you, could you please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

 

hi @Anonymous ,

A simplified part of the direct query data table is: column title with datatype in ()

Ticket (text)Date Created (date)Time Created (time)DateTime Created (datetime)Target Days (general)
RFC2011060016-11-20208:47:186-11-2020 8:473
SO2011060016-11-20209:18:006-11-2020 9:180,5
SO2011060026-11-20209:23:136-11-2020 9:233
SO2011060036-11-20209:29:156-11-2020 9:295
RFC2011060026-11-20209:30:596-11-2020 9:303
SO2011060056-11-20209:58:106-11-2020 9:5815
RFC2011060036-11-202010:01:496-11-2020 10:010,5
SO2011060066-11-202010:03:336-11-2020 10:033
SO2011060086-11-202010:13:006-11-2020 10:13

15

 

and the calendar table is (simplified) as you already have created in 

JC2022_0-1690969092492.png

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.