Need one function

Hi Team,

 

I want to create one expression rule which will return me number of months and quarter on basis of input.

Like if I JUN as month and period is 4 than rule should return MAR,APR,MAY,JUN,Q1,Q2

 

FEB is month and period is 4 than it should return JAN,FEB,Q1

 

SEP,8-> OCT,SEP,AUG,JUL,JUN,MAY,APR,MAR,Q1,Q2

 

Kindly help me out for this rule.

I am unable to prepare this rule.

 

 

 

  Discussion posts and replies are publicly visible

Parents
  • Hi  ,

    Here is the code for the function.

    load(
      local!months: {
        "JAN",
        "FEB",
        "MAR",
        "APR",
        "MAY",
        "JUN",
        "JUL",
        "AUG",
        "SEP",
        "OCT",
        "NOV",
        "DEC"
      },
      local!quarter: {
        "Q1",
        "Q2",
        "Q3",
        "Q4"
      },
      /* To calculate the actual period */
      local!period: if(
        ri!period - wherecontains(
          ri!month,
          local!months
        ) > 0,
        ri!period - (
          ri!period - wherecontains(
            ri!month,
            local!months
          )
        ),
        ri!period
      ),
      local!temp1: ldrop(
        local!months,
        wherecontains(
          ri!month,
          local!months
        ) - local!period
      ),
      local!temp2: rdrop(
        local!temp1,
        length(
          local!temp1
        ) - wherecontains(
          ri!month,
          local!temp1
        )
      ),
      append(
        local!temp2,
        index(
          local!quarter,
          union(
            roundup(
              wherecontains(
                local!temp2,
                local!months
              ) / 3,
              0
            ),
            todecimal(
              {}
            )
          )
        )
      )
    )
     
     
    Hope this helps!
Reply
  • Hi  ,

    Here is the code for the function.

    load(
      local!months: {
        "JAN",
        "FEB",
        "MAR",
        "APR",
        "MAY",
        "JUN",
        "JUL",
        "AUG",
        "SEP",
        "OCT",
        "NOV",
        "DEC"
      },
      local!quarter: {
        "Q1",
        "Q2",
        "Q3",
        "Q4"
      },
      /* To calculate the actual period */
      local!period: if(
        ri!period - wherecontains(
          ri!month,
          local!months
        ) > 0,
        ri!period - (
          ri!period - wherecontains(
            ri!month,
            local!months
          )
        ),
        ri!period
      ),
      local!temp1: ldrop(
        local!months,
        wherecontains(
          ri!month,
          local!months
        ) - local!period
      ),
      local!temp2: rdrop(
        local!temp1,
        length(
          local!temp1
        ) - wherecontains(
          ri!month,
          local!temp1
        )
      ),
      append(
        local!temp2,
        index(
          local!quarter,
          union(
            roundup(
              wherecontains(
                local!temp2,
                local!months
              ) / 3,
              0
            ),
            todecimal(
              {}
            )
          )
        )
      )
    )
     
     
    Hope this helps!
Children