Skip to main content

条件として 

課金開始日が2026年1月1日で今日が2026年4月1日の場合 

①解約日が決まっていない(NULL) 

 MONTH(TODAY())-MONTH(課金開始日__C)+1 → 4-1+1=4  

②解約日が2026年10月31日の場合 

 MONTH(MIN(課金解約日__c,TODAY()))-MONTH(課金開始日__C)+1 → 4-1+1=4 

③解約日が2027年1月31日の場合は2026年分のみ計算したい。 

 

この①~③を全て満たす数式を教えて頂きたく。 

 

#Trailhead Challenges  #Trailhead  #Salesforce Admin

2 risposte
  1. 15 set, 16:16

    Hi Aramaki-san, 

    To cover all three cases, I’d recommend including the year in the calculation instead of using only MONTH(). 

    You can use: 

    IF(

    ISBLANK(課金解約日__c),

    (YEAR(TODAY()) - YEAR(課金開始日__c)) * 12

    + MONTH(TODAY()) - MONTH(課金開始日__c) + 1,

    (YEAR(MIN(課金解約日__c, TODAY())) - YEAR(課金開始日__c)) * 12

    + MONTH(MIN(課金解約日__c, TODAY())) - MONTH(課金開始日__c) + 1

    )

      

    For example: 

     

    •  Start: Jan 1, 2026 / Today: Apr 1, 2026 → 4 months
    •  Cancellation: Oct 31, 2026 / Today: Apr 1, 2026 → 4 months
    •  Cancellation: Jan 31, 2027 / Today: Apr 1, 2026 → 4 months

     

    The key point is using YEAR() together with MONTH() so the calculation also works correctly when the dates cross into another year. 

     

0/9000