Forum Discussion

cdn4lf's avatar
cdn4lf
Frequent Visitor
7 years ago
Solved

Calculate End Date

Hi All,

 

I'm looking for some help in calculating an end date for the image below OR for a way to determine the correct fee amount based on the course_fee_id being the same AND the start date of the course (linked table), being greater than or equal to the effective date, but less than the next effective date.

 

The source date/fee data is below.  The table that needs to call on the fee amount based on fee_id and Effective_date is a separate table.

 

 

 

Thanks!

 

  • hi, cdn4lf 

    You could use this formula to add a Effective_End_Date column in table 1, then create another column in table2

     

    Effective_End_Date =
    IF (
        CALCULATE (
            MIN ( Table1[Effective_Start_Date] ),
            FILTER (
                Table1,
                Table1[Fee_ID] = EARLIER ( Table1[Fee_ID] )
                    && Table1[Effective_Start_Date] > EARLIER ( Table1[Effective_Start_Date] )
            )
        )
            = BLANK (),
        DATE ( 9999, 12, 31 ),
        CALCULATE (
            MIN ( Table1[Effective_Start_Date] ),
            FILTER (
                Table1,
                Table1[Fee_ID] = EARLIER ( Table1[Fee_ID] )
                    && Table1[Effective_Start_Date] > EARLIER ( Table1[Effective_Start_Date] )
            )
        ) - 1
    )

    Best regards,
    Lin

6 Replies

    • cdn4lf's avatar
      cdn4lf
      Frequent Visitor

      Hello,

       

      Please see below.  I've provided two possible outputs, that should both do what I need.  Table #1 and Table #2, are linked by the Fee_ID and linked across, such that the fee used matches the Fee_ID and the effective date is less than the start date, BUT, also less than the next effective date for that Fee_ID.

       

      Fee_IDEffective DateFee Amount
      12002/01/010
      12003/01/160
      12004/01/310
      12005/02/140
      12006/03/011
      12007/03/161
      12008/03/301
      22002/01/0245
      22003/01/1735
      22004/02/0148
      22005/02/1549
      22006/03/0260
      22007/03/1755
      22008/03/3158.75
      22002/01/0362
      32003/01/1812
      32004/02/0213
      32005/02/1614
      32006/03/0315
      32007/03/1819
      32008/04/0122
      32002/01/0422.75
      32003/01/1938
      42004/02/03150
      42005/02/17151
      42006/03/04156
      42007/03/19175
      42008/04/02180
      42002/01/05200
      42003/01/20

      195

       

      Course_IDFee_IDStart_Date
      112002/02/20
      222002/04/02
      332003/04/03
      442004/04/03
      512006/04/20
      622006/05/31
      732007/06/01
      842008/06/01
      912004/03/21
      1022002/04/03
      1132003/04/04
      1242003/03/21
      1312008/05/19
      1422005/05/16
      1532005/05/02
      1642005/12/14
      1712007/05/05
      1822004/05/03
      1932008/06/15
      2042004/11/26
      2112003/03/07
      2222008/07/01
      2332002/03/21
      2442004/11/26
      2512008/05/19
      2622004/05/02

       

      Output Option #1 (Ideal)
      Course_IDFee_IDStart_DateFee Amount
      112002/02/200
      222002/04/0245
      332003/04/0312
      442004/04/03150
      512006/04/201
      622006/05/3160
      732007/06/0119
      842008/06/01180
      912004/03/210
      1022002/04/0345
      1132003/04/0412
      1242003/03/210
      1312008/05/191
      1422005/05/1649
      1532005/05/0214
      1642005/12/14151
      1712007/05/051
      1822004/05/0348
      1932008/06/1522
      2042004/11/26150
      2112003/03/070
      2222008/07/0158.75
      2332002/03/210
      2442004/11/26150
      2512008/05/191
      2622004/05/0249

       

      Output Option #2 (would allow for a lookup based on between)
      Fee_IDStart_DateEnd_DateFee Amount
      12002/01/012003/01/150
      12003/01/162004/01/300
      12004/01/312005/02/130
      12005/02/142006/02/280
      12006/03/012007/03/151
      12007/03/162008/03/291
      12008/03/30 1
      22002/01/022003/01/1645
      22003/01/172004/01/3135
      22004/02/012005/02/1448
      22005/02/152006/03/0149
      22006/03/022007/03/1660
      22007/03/172008/03/3055
      22008/03/312009/01/0258.75
      22009/01/03 62
      32003/01/182004/02/0112
      32004/02/022005/02/1513
      32005/02/162006/03/0214
      32006/03/032007/03/1715
      32007/03/182008/03/3119
      32008/04/012009/01/0322
      32009/01/042010/01/1822.75
      32010/01/19 38
      42004/02/032005/02/16150
      42005/02/172006/03/03151
      42006/03/042007/03/18156
      42007/03/192008/04/01175
      42008/04/022009/01/04180
      42009/01/052010/01/19200
      42010/01/20 195

       

       

      • v-lili6-msft's avatar
        v-lili6-msft
        Community Support

        hi, cdn4lf 

        For your case, I recommend you add a start and end date for Effective Date in table1

        Then use this formula to add a column.

         

        Column = CALCULATE(SUM(Table1[Fee Amount]),FILTER(RELATEDTABLE(Table1),Table1[Effective_Start_Date]<=Table2[Start_Date]&&Table2[Start_Date]<=Table1[Effective_End_Date]))+0

        Buy the way, for the last Effective Date, add 12/31/9999 for end date

         

        Result:

        Note: For courseID 26, the correct result should be 48

         

        and here is pbix file, please try it.

         

        Best Regards,

        Lin