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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Adding working days

Hello,

 

I am trying to add working days to a date if certain conditions are respected to create a target date. I have tried many things from the internet but nothing works and i'm more lost now than I was before. 

I created a new request with a list of dates from 2017 to 2023, I created a column that writes 1 if it's a working day and 0 if it's not (Jours ouvrés). (I downloaded an excel file with the holydays)

Loladba_0-1652708223377.png

That request works.

Now I have another query where I have the Date column I want to add 7 working days to, if certain conditions are met: IF(NOT(ISBLANK('Tracking'[RELANCE 1])) && Tracking[CONFORMITE]="FAUX", IF( ISBLANK('Tracking'[Document reçu]) || ISBLANK(Tracking[Date réception document]),

then add 7 days to 'Tracking'[RELANCE 1], else BLANK()),BLANK())

 

I have tried a few things like creating these columns (https://community.powerbi.com/t5/Desktop/Add-working-days-to-a-date/m-p/146945)  : Rank1 = RANKX(FILTER(Calendrier,Calendrier[Jours ouvrés]=1),Calendrier[Dates],,ASC)
+ 10 jours ouvrés = LOOKUPVALUE(Calendrier[Dates],Calendrier[Jours ouvrés],1,Calendrier[Rank1],Calendrier[Rank1]+10)
+ 7 jours ouvrés 

But I'm stuck when I have to relate the Calendrier query and my other query (where I have the column I want to add working day).

I wanted to create a relationship between them, which I did but I could only choose multiple to multiple and when I use the RELATE function like in the link it doesn't find the table.

 

Can anyone help me?

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

 

Relationships will propagate filters between tables so it is not allowed to have multiple active relationships between tables to avoid ambiguity. If you are not familiar with active/inactive relationships, you can refer to this guide: Active vs inactive relationship guidance 

 

In addition, the RELATED function requires that an active relationship exists between the current table and the table with related information. If you want to get the +7 working date according to Relance 2 or Relance 3, you can try below code. This code is not dependent on the relationship. 

 

Column 2 =
MAXX (
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] = EARLIER ( 'Tracking (2)'[RELANCE 2] )
    ),
    'Calendar'[+ 7 Working Days]
)

 

vjingzhang_0-1653013497257.png

 

If this is not what you want, can you please show what you want to do with Relance 2 and Relance 3?

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

10 REPLIES 10
rohit_singh
Solution Sage
Solution Sage

Hello @Anonymous ,

First of all please ensure that you're using the inbuilt date functionalities in Power BI to compute working days, rather than using an external lookup file. 
In Power Query, add the following column to your date table (calendrier)

rohit_singh_0-1652712760980.png

Assuming Monday as the first day of the week, it is assgined a value of 0. Hence, Saturday and Sunday have values 5 and 6 respectively.
You now get the column Jours ouvrés without using an external lookup.

rohit_singh_1-1652712792984.png


I have assumed hat your Tracking table looks like below

rohit_singh_3-1652713800045.png
In the report view, create a 1:M relationship between your date table and the Tracking table

rohit_singh_2-1652713749022.png

Once this relationship has been created, go to your Tracking table and add a new column based on the relationship created above. This will give you the weekday flag as a column on the Tracking table

Jours ouvrés = RELATED(dim_date[Jours ouvrés])

rohit_singh_4-1652713933811.png


Next, based on your requirement add a new column. To add 7 days to the given date use 

DATEADD(Tracking[RELANCE 1], 7 ,DAY)

rohit_singh_5-1652714284500.png

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 😊

 

Anonymous
Not applicable

Thank you so much.

 

It's not working though, it says The "DATEADD" function expects a contiguous selection when the date column is not unique, is discontinuous, or contains a time part.

Hi @Anonymous ,

Please ensure that your date columnis formatted as date and not date/time.

rohit_singh_3-1652718669873.png

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos!  😊

 

Anonymous
Not applicable

Hello @rohit_singh,

 

I Checked and the column is in Date and not Date time but It may be because the column of dates is discontinued (sometimes there are dates, sometimes it's empty).

I did it many times in different ways, I don't always get the message but in any case it doesn't add the days, the column where it's supposed to be +7 days is completly empty.

Hi @Anonymous 

 

I create a sample demo attached at bottom. See if it helps. 

 

First create a new column in the calendar table to get the +7 working date for every date. 

+ 7 Working Days = 
MAXX (
    TOPN (
        7,
        FILTER (
            'Calendar',
            'Calendar'[Date] > EARLIER ( 'Calendar'[Date] )
                && 'Calendar'[IsWorkingDay] = 1
        ),
        'Calendar'[Date], ASC
    ),
    'Calendar'[Date]
)

vjingzhang_0-1652949078544.png

 

Then in 'Tracking' table, get the +7 working date with RELATED function. 

vjingzhang_1-1652949249268.png

 

The relationship between two tables as below. 

vjingzhang_2-1652949269407.png

 

If 'RELANCE 1' value is blank, it returns blank too. 

vjingzhang_3-1652949513723.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Anonymous
Not applicable

Hello @v-jingzhang ,

 

Thank you so much! It works!!! Now the only problem I have is that I want to that with 2 different columns in the same query: Relance 2 and Relance 3

Loladba_1-1652956572759.png

 

But when I try to create a relation between Dates from the query Calendrier and Relance 2 and Relance 3 from tracking query it says I can't create 2 relations. Would you know how I can fix that?

Hi @Anonymous 

 

Relationships will propagate filters between tables so it is not allowed to have multiple active relationships between tables to avoid ambiguity. If you are not familiar with active/inactive relationships, you can refer to this guide: Active vs inactive relationship guidance 

 

In addition, the RELATED function requires that an active relationship exists between the current table and the table with related information. If you want to get the +7 working date according to Relance 2 or Relance 3, you can try below code. This code is not dependent on the relationship. 

 

Column 2 =
MAXX (
    FILTER (
        ALL ( 'Calendar' ),
        'Calendar'[Date] = EARLIER ( 'Tracking (2)'[RELANCE 2] )
    ),
    'Calendar'[+ 7 Working Days]
)

 

vjingzhang_0-1653013497257.png

 

If this is not what you want, can you please show what you want to do with Relance 2 and Relance 3?

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Anonymous
Not applicable

Thank you so much @v-jingzhang !!!!! It's exactly what I wanted and it works !!!!

amitchandak
Super User
Super User

Anonymous
Not applicable

Hi @amitchandak ,

 

thank you for your answer. I don't understand everything. I Think I have done that. I have this:

Loladba_0-1652714240600.png

The problem is that I want to add the 7 working days to another date column in a another request. 

That second part, I don't get?:

Plus 10 Days = var _max =maxx(ALLSELECTED('Date'),'Date'[Work Date cont Rank])
return
CALCULATE(Min('Date'[Date]),filter(ALL('Date'),'Date'[Work Date  Rank] =_max+10))

Rolling Last 10 Days =  CALCULATE(SUM(Sales[Net Sales]),FILTER(all('Date'),'Date'[Work Date cont Rank]>=min('Date'[Work Date cont Rank])-10 
				&& 'Date'[Work Date cont Rank]<=max('Date'[Work Date cont Rank])))

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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