Forum Discussion
barend_dronkers
4 years agoRegular Visitor
Contract renewal, cancellation and renewal amount increase/decrease
I have a Contract table that includes the following columns: ID Account Service Start Date End Date Amount ($) 1 Account A Service 1 2021/05/18 ...
- 4 years ago
Hi barend_dronkers
Here is a sample file with the solution https://www.dropbox.com/t/MHLqHgqhR8T8rNOcAction = VAR ContractsTable = Contracts VAR LatestContractEnd = MAXX ( ContractsTable, Contracts[End Date] ) VAR LastContractStart = MAXX ( ContractsTable, Contracts[Start Date] ) VAR PreviousContracts = FILTER ( ContractsTable, Contracts[End Date] < LatestContractEnd ) VAR Last2ndContractEnd = MAXX ( PreviousContracts, Contracts[End Date] ) VAR ContractGap = DATEDIFF ( Last2ndContractEnd, LastContractStart, DAY ) VAR Result = SWITCH ( TRUE ( ), LatestContractEnd <= TODAY ( ), "Cancel", ISBLANK ( Last2ndContractEnd ) || ContractGap > 1, "New", "Renew" ) RETURN ResultMost Recent Contract ID = MAX ( Contracts[ID] )Renewal Rate (%) = VAR ContractsTable = Contracts VAR LatestContractEnd = MAXX ( ContractsTable, Contracts[End Date] ) VAR LastContractValue = MAXX ( FILTER ( ContractsTable, Contracts[End Date] = LatestContractEnd ), Contracts[Amount ($)] ) VAR PreviousContracts = FILTER ( ContractsTable, Contracts[End Date] < LatestContractEnd ) VAR PreviousContractEnd = MAXX ( PreviousContracts, Contracts[End Date] ) VAR PreviousContractValue = MAXX ( FILTER ( PreviousContracts, Contracts[End Date] = PreviousContractEnd ), Contracts[Amount ($)] ) RETURN IF ( [Action] = "Renew", DIVIDE ( LastContractValue, PreviousContractValue) )
barend_dronkers
4 years agoRegular Visitor
Thank you!! It might actually make more sense to not create an extra table. I'm going to give this a try today. Also appreciate understanding your logic!
barend_dronkers
4 years agoRegular Visitor
Hi James. I like that your solution uses columns, because it means I can use a slicer visual to filter on the type of action. One problem I'm running into with your solution is that _nbrows counts total number of rows, regardless of whether the previous contracts are actually earlier in time. Action should only flag something as "renew" if the previous contract's EndDate (if any exist) is adjacent (1 day less) than the StartDate of the contract we're flagging as a "renew".