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

Complex Calculated Column

Hi Team,

 

How do I create a calculated column that adds the 2 columns? I have 2 tables - Table1 and Date table.


Table1: -

Date1Add_DaysFinal Date
1/1/201710 
1/2/201715 
1/3/201720 
1/4/201725 
1/5/201730 
1/6/201735 
1/7/201740 
1/8/201745 

 

Date Table:-

DateWorkDay
1/1/20171
1/2/20171
1/3/20171
1/4/20170
1/5/20170
1/6/20171
1/7/20171
1/8/20170

The idea is to calculate FinalDate = Date1+AddDays in the first table. However, the second table contains workday indicator. If it's 0, then it is holiday. So we only need to add days for which there are 1 in the date table.
If I directly add, it takes all the days. How can I calculate Final Date by ignoring non-working days from the second table?

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create relationship between Table1 and Date table on date field first of all, then create columns in Date table like DAX below.

 

Rank1 = RANKX(FILTER(Date, Date[WorkDay]=1),Date[Date],,ASC)
 
Add working days = LOOKUPVALUE(Date[Date],Date[WorkDay],1,Date[Rank1],Date[Rank1]+RELATED(Table1[Add_Days]))

 

Finally, you can create column in Table1.

 

Final Date=RELATED(Calendar[Add working days])

 

Best Regards,

Amy

 

Community Support Team _ Amy

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

10 REPLIES 10
v-xicai
Community Support
Community Support

Hi  @Anonymous  ,

 

Does that make sense? If so, kindly mark the proper reply as a solution to help others having the similar issue and close the case. If not, let me know and I'll try to help you further.

 

Best regards

Amy

v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create relationship between Table1 and Date table on date field first of all, then create columns in Date table like DAX below.

 

Rank1 = RANKX(FILTER(Date, Date[WorkDay]=1),Date[Date],,ASC)
 
Add working days = LOOKUPVALUE(Date[Date],Date[WorkDay],1,Date[Rank1],Date[Rank1]+RELATED(Table1[Add_Days]))

 

Finally, you can create column in Table1.

 

Final Date=RELATED(Calendar[Add working days])

 

Best Regards,

Amy

 

Community Support Team _ Amy

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

VasTg
Memorable Member
Memorable Member

@Anonymous 

 

Please try this DAX. Hope you might have 1 to many relationship from Table2 to Table1.

 

Column = VAR END_DATE = 'Table 1'[Date1]+'Table 1'[Add_Days]
RETURN 'Table 1'[Date1]+CALCULATE(SUM('Table 2'[WorkDay]),FILTER('Table 2','Table 2'[Date]>='Table 1'[Date1]&&'Table 2'[Date]<=END_DATE))
 
 
If it helps, mark it as a solution.
Kudos are nice too.
Connect on LinkedIn
parry2k
Super User
Super User

@Anonymous assuming you have relationship between these two tables on date column, here is what you do to add

Final Date = 
IF ( RELATED ( DateTable[WorkDay] ) = 1, Table1[Date1] + Table1[Add_Days], Table1[Date1] )

 

Add your logic in else condition  whatever you want, I currently put Table1[Date1] in case workday = 0



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

VasTg
Memorable Member
Memorable Member

@parry2k 

 

Good to know this option.

 

But the IF condition fails when the date is a holiday. Could you fix it?

 

 

 

 

Connect on LinkedIn

@VasTg can you explain little bit more, what you mean by fail? Error message or what?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

VasTg
Memorable Member
Memorable Member

@parry2k 

 

When the date from table is marked as holiday(workday = 0), the IF condition is false and the else part is executed.

In my example 1,5,6 are holidays.

 

Cap11.PNG

Table1 

 

Date1Add_Days

1/1/201910
1/2/201910
1/3/201920
1/4/201925
1/5/201930
1/6/201935
1/7/201940
1/8/201945

 

 

Table 2

1/1/20190
1/2/20191
1/3/20191
1/4/20191
1/5/20190
1/6/20190
1/7/20191
1/8/20191
1/9/20191
1/10/20191
1/11/20191
1/12/20190
1/13/20190
1/14/20191
1/15/20191
1/16/20191
1/17/20191
1/18/20191
1/19/20190
1/20/20190
1/21/20191
1/22/20191
1/23/20191
1/24/20191
1/25/20191
1/26/20190
1/27/20190
1/28/20191
1/29/20191
1/30/20191
1/31/20191
2/1/20191
2/2/20190
2/3/20190
2/4/20191
2/5/20191
2/6/20191
2/7/20191
2/8/20191
2/9/20190
2/10/20190
2/11/20191
2/12/20191
2/13/20191
2/14/20191
2/15/20191
2/16/20190
2/17/20190
2/18/20191
2/19/20191
2/20/20191
2/21/20191
2/22/20191
2/23/20190
2/24/20190
2/25/20191
2/26/20191
2/27/20191
2/28/20191

 

 

Hope it helps.

 

 

By the way, which option should I use to post the DAX in the forum which appears in a box in your replies.. Table->cell?

Connect on LinkedIn

@VasTg I asked you in original reply what you want when workday is 0 (in other words false condition). In your post you mentioned what you want if workday = 1, add days to get final date but what you want when workday is 0???



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

VasTg
Memorable Member
Memorable Member

@parry2k 

 

I didn't start the thread.

 

The orinigal ask was to ignore the holidays. Either you misunderstood the inital ask or you didn't test your DAX. Read the first post again.

Connect on LinkedIn

@VasTg I know my DAX and I read the posts carefully, although thanks for reminding. I'm sorry I thought you started the post. Anyhow will wait @Anonymous to reply to see what he wants in case of Else.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.

Top Solution Authors