Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Calculate Prior Date based on unique field

Hello,

 

In the list below, for each row, I need to find the next effective date (effdt) based [PlanLink], sort of like a sumifs in Excel. What I am trying to do is get each effective date's End Date by finding its next effective date and subtracting a day. In the instances were the latest plan is still the most recent I just want to set the end date as some far off date like 12/31/2099 or something.

 

I have included a live data set as well as manually assigned the first several rows on [EndDate] to illustrate what I am trying to do. Again, each EndDate should be looking at EffDtg and unique [PlanLink] fields.

 

 

Customer_IDContractEffDtMapPlan NamePlanLinkEndDate
2990916907601/01/14D0012737Bronze (PPO)0169076D0012737Bronze (PPO)12/31/14
2990916907601/01/15D0012737Bronze (PPO)0169076D0012737Bronze (PPO)12/31/15
2990916907601/01/16D0012737Bronze (PPO)0169076D0012737Bronze (PPO)12/31/16
2990916907601/01/17D0012737Bronze (PPO)0169076D0012737Bronze (PPO)12/31/99
2990916907601/01/14D0012738Silver (PPO)0169076D0012738Silver (PPO)12/31/14
2990916907601/01/15D0012738Silver (PPO)0169076D0012738Silver (PPO)12/31/15
2990916907601/01/16D0012738Silver (PPO)0169076D0012738Silver (PPO)12/31/16
2990916907601/01/17D0012738Silver (PPO)0169076D0012738Silver (PPO)12/31/99
2990916907601/01/14D0012739Gold (PPO)0169076D0012739Gold (PPO)12/31/14
2990916907601/01/15D0012739Gold (PPO)0169076D0012739Gold (PPO)12/31/15
2990916907601/01/16D0012739Gold (PPO)0169076D0012739Gold (PPO)12/31/16
2990916907601/01/17D0012739Gold (PPO)0169076D0012739Gold (PPO)12/31/99
2990916907601/01/16D0012745Platinum (DHMO)0169076D0012745Platinum (DHMO)12/31/16
2990916907601/01/17D0012745Platinum (DHMO)0169076D0012745Platinum (DHMO)12/31/99
2990916907601/01/16D0012751Platinum (DHMO)0169076D0012751Platinum (DHMO)12/31/16
2990916907601/01/17D0012751Platinum (DHMO)0169076D0012751Platinum (DHMO)12/31/99
2990916907601/01/16D0012794Platinum (DHMO)0169076D0012794Platinum (DHMO)12/31/16
2990916907601/01/17D0012794Platinum (DHMO)0169076D0012794Platinum (DHMO)12/31/99
2990916907601/01/16D0012795Platinum (DHMO)0169076D0012795Platinum (DHMO)12/31/16
2990916907601/01/17D0012795Platinum (DHMO)0169076D0012795Platinum (DHMO)12/31/99
2990916907601/01/16D0013549Platinum (DHMO)0169076D0013549Platinum (DHMO)12/31/16
2990916907601/01/17D0013549Platinum (DHMO)0169076D0013549Platinum (DHMO)12/31/99
25446622770401/01/16D0012737Bronze (PPO)0227704D0012737Bronze (PPO)12/31/99
25446622770401/01/16D0012738Silver (PPO)0227704D0012738Silver (PPO)12/31/99
25357624171401/01/07D0012739Gold (PPO)0241714D0012739Gold (PPO)12/31/07
25357624171401/01/08D0012739Gold (PPO)0241714D0012739Gold (PPO)12/31/99
6188524235901/01/18D0012737Bronze (PPO)0242359D0012737Bronze (PPO)12/31/17
6188524235901/01/18D0012738Silver (PPO)0242359D0012738Silver (PPO) 
6188524235901/01/18D0012739Gold (PPO)0242359D0012739Gold (PPO) 
6188524235901/01/18D0012745Platinum (DHMO)0242359D0012745Platinum (DHMO) 
6188524235901/01/18D0012751Platinum (DHMO)0242359D0012751Platinum (DHMO) 
6188524235901/01/18D0012794Platinum (DHMO)0242359D0012794Platinum (DHMO) 
6188524235901/01/18D0012795Platinum (DHMO)0242359D0012795Platinum (DHMO) 
6188524235901/01/18D0013549Platinum (DHMO)0242359D0013549Platinum (DHMO) 
2451970111501/01/05D0012737Bronze (PPO)0701115D0012737Bronze (PPO) 
2451970111501/01/05D0012738Silver (PPO)0701115D0012738Silver (PPO) 
2451970111501/01/05D0012739Gold (PPO)0701115D0012739Gold (PPO) 
15725270414004/01/16D0012737Bronze (PPO)0704140D0012737Bronze (PPO) 
15725270414001/01/17D0012737Bronze (PPO)0704140D0012737Bronze (PPO) 
15725270414001/01/18D0012737Bronze (PPO)0704140D0012737Bronze (PPO) 
15725270414004/01/16D0012738Silver (PPO)0704140D0012738Silver (PPO) 
15725270414001/01/17D0012738Silver (PPO)0704140D0012738Silver (PPO) 
15725270414001/01/18D0012738Silver (PPO)0704140D0012738Silver (PPO) 
15725270414004/01/16D0012739Gold (PPO)0704140D0012739Gold (PPO) 
  • Hi Anonymous

     

    You may add an index column in query editor first. Then you may create the below calculated columns.

    Group =
    IF (
        Table4[PlanLink]
            = LOOKUPVALUE ( Table4[PlanLink], Table4[Index], Table4[Index] + 1 ),
        0,
        1
    )
    

     

    EndDate =
    IF (
        Table4[Group] = 0,
        LOOKUPVALUE ( Table4[EffDt], Table4[Index], Table4[Index] + 1 )
            - 1,
        DATEVALUE ( "12/31/2099" )
    )
    

     

     

    Regards,

    Cherie

1 Reply

  • v-cherch-msft's avatar
    v-cherch-msft
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi Anonymous

     

    You may add an index column in query editor first. Then you may create the below calculated columns.

    Group =
    IF (
        Table4[PlanLink]
            = LOOKUPVALUE ( Table4[PlanLink], Table4[Index], Table4[Index] + 1 ),
        0,
        1
    )
    

     

    EndDate =
    IF (
        Table4[Group] = 0,
        LOOKUPVALUE ( Table4[EffDt], Table4[Index], Table4[Index] + 1 )
            - 1,
        DATEVALUE ( "12/31/2099" )
    )
    

     

     

    Regards,

    Cherie