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
Seizera
New Member

Filter ID's which have contract not active currently

Hello,

 

I have a table where i have contracts which can be either "Ended" "Active" and they can have the same ID. Example data:

 

Start dateEnd dateContract stateContract ID
9.3.2020 Active1
13.08.20198.3.2020Ended1

 

Like this. I want to have a list of contract ID's which have their last status as Ended. How can i do this?

 

Use case is as follows:

I have 20 000 contracts and i want to know which have ended, so they don't have a new active contract starting after the Ended row in database.

If i filter by Ended only, for example this contract ID 1 would show me that it only has a Ended row, when it does have an Active row aswell and thus is a running contract.

 

Hopefully i explained this properly, i could not make up a solution myself to a quite easy problem, still trying to learn the ropes of PowerBI.

Thanks in advance,

Mikael

 

1 ACCEPTED SOLUTION
lkalawski
Memorable Member
Memorable Member

To do this, you need to perform several operations in Power Query:

  1. With this data set, group it by ContractID and leave the maximum Start and End Date values for each ID.Ex1.pngEx2.png
    The result:
     Ex3.png
  2. Then add a condition that checks whether Max (Start Date)> Max (End Date). If so, it means that the contract is still active. If not, it means it's over.
    Ex2.png
  3. Then merged the data with your starting table (in blue), expand it and remove unnecessary columns.Ex5.png
  4. The result:
    Ex6.png

 

View solution in original post

4 REPLIES 4
lkalawski
Memorable Member
Memorable Member

To do this, you need to perform several operations in Power Query:

  1. With this data set, group it by ContractID and leave the maximum Start and End Date values for each ID.Ex1.pngEx2.png
    The result:
     Ex3.png
  2. Then add a condition that checks whether Max (Start Date)> Max (End Date). If so, it means that the contract is still active. If not, it means it's over.
    Ex2.png
  3. Then merged the data with your starting table (in blue), expand it and remove unnecessary columns.Ex5.png
  4. The result:
    Ex6.png

 

Hi!

Thanks for the quick reply.

I found this to be mostly working, only thing where it doesnt seem to work properly is a case like this:

startdateenddateactivecontractid 
25.2.2019 21:00:0020.1.2020 22:00:00ended1 
20.1.2020 22:00:00 active1 

 

For situation like this it seems like this contract would show up as non active but it is indeed active. Contracts should always have a time difference (1 day usually) but sometimes this is not the case.

Is there any possible solution to quickly filter these out aswell?
I was thinking of doing startdate = enddate => filter out, but would that work properly.

Thanks!

 

This change of condition will help. Especially when you compare datetime. If startdate> = end date it means that it is still active.

Ex7.pngEx8.png

 

If I helped, please accept the solution! 🙂

Thanks!

Hey,

 

It did, thanks for the help! Accepted the solution.

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.