cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Hofstede
Regular Visitor

Dates issue: is a contract active in year 2017?

Hi!

 

I have two date columns in Power BI. One states the first day of a work contract, the second the end date. My boss wants to know how many contracts were 'active' in year 2017. And how many in 2018, etc. The idea is to make a slicer. 

 

I thought I'd create new columns, called 'Working in 2017' and so on. I'm looking for a query or Dax function that will retrun a Yes (or 1) or No (or 0). So someone who started working on 1-1-2018 and will stop midway 2019, will get a No at 'Working in 2017' and a Yes at 'Working in 2018' and 'Working in 2019'.

 

Hoping someone can and will help me. Thanks!

 

date.PNG

example.PNG

 

1 ACCEPTED SOLUTION
StanTheMan
Frequent Visitor

Hi, @Hofstede @Anonymous 

With the previous solution a startdate of contract in 2016 and enddate in 2018 won't be active in 2017 right?

So maybe something like this in DAX:
Working in 2017 = if( TABLE[Start Contract] <= DATE(2017;12;31 ) && TABLE[End Contract] >= DATE(2017;1;1); "Yes"; "No" )
Working in 2018 = if( TABLE[Start Contract] <= DATE(2018;12;31 ) && TABLE[End Contract] >= DATE(2018;1;1); "Yes"; "No" )
Working in 2019 = if( TABLE[Start Contract] <= DATE(2019;12;31 ) && TABLE[End Contract] >= DATE(2019;1;1); "Yes"; "No" )

Correct me if i'm wrong!

Kind regards,

View solution in original post

3 REPLIES 3
Hofstede
Regular Visitor

Worked like a charm! Thanks @StanTheMan!

StanTheMan
Frequent Visitor

Hi, @Hofstede @Anonymous 

With the previous solution a startdate of contract in 2016 and enddate in 2018 won't be active in 2017 right?

So maybe something like this in DAX:
Working in 2017 = if( TABLE[Start Contract] <= DATE(2017;12;31 ) && TABLE[End Contract] >= DATE(2017;1;1); "Yes"; "No" )
Working in 2018 = if( TABLE[Start Contract] <= DATE(2018;12;31 ) && TABLE[End Contract] >= DATE(2018;1;1); "Yes"; "No" )
Working in 2019 = if( TABLE[Start Contract] <= DATE(2019;12;31 ) && TABLE[End Contract] >= DATE(2019;1;1); "Yes"; "No" )

Correct me if i'm wrong!

Kind regards,

View solution in original post

Anonymous
Not applicable

=IF(AND([Start Contract]>=DATE(2017,1,1),[End Contract]>=DATE(2017,12,31),1,0)

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Top Solution Authors
Top Kudoed Authors