Question

I wanted to create quarter section but without the ceiling function because I have specific dates for each quarter. first quarter is from the 22 of October to the 21 to January. so I've created this function: (in the loadscript)

 if((Month(RetDate)='10' AND Day(RetDate)>21) OR (Month(RetDate) = '11' OR Month(RetDate) = '12') OR (Month(RetDate)='1' AND Day(RetDate)<22),'Q1',
        if((Month(RetDate)='1' AND Day(RetDate)>21) OR (Month(RetDate) = '2' OR Month(RetDate) = '3') OR (Month(RetDate)='4' AND Day(RetDate)<22),'Q2',
        if((Month(RetDate)='4' AND Day(RetDate)>21) OR (Month(RetDate) = '5' OR Month(RetDate) = '3') OR (Month(RetDate)='6' AND Day(RetDate)<22),'Q3','Q4'))) as Quarter1,

But in this way, for example, 23.10.13 (23 OCT.) is related to Q1 of 2013 instead of Q1 of 2014.

thanks :)

Was it helpful?

Solution

Ceil( Month( If( if(Day(RetDate)<22,RetDate,QuarterStart(RetDate,1)) )/3) as Quarter

so if the date is after the 22 i push it a quarter forward.

OTHER TIPS

I think this is what you are looking for:

LOAD Customer,
         RetDate,

     if(Month(RetDate)='1', 
         if(Day(RetDate)<22, 'Q1', 'Q2'),
     if(Month(RetDate)='2', 'Q2',
     if(Month(RetDate)='3', 'Q2',
     if(Month(RetDate)='4', 
         if(Day(RetDate)<22, 'Q2', 'Q3'),
     if(Month(RetDate)='5', 'Q3',
     if(Month(RetDate)='6', 'Q3',
     if(Month(RetDate)='7', 
         if(Day(RetDate)<22, 'Q3', 'Q4'),
     if(Month(RetDate)='8', 'Q4',
     if(Month(RetDate)='9', 'Q4',
     if(Month(RetDate)='10', 
         if(Day(RetDate)<22, 'Q4', 'Q1'),
     if(Month(RetDate)='11', 'Q1',
     if(Month(RetDate)='12', 'Q1',
     'undef' )))))))))))) as Quarter,
 INLINE [
Customer, RetDate
A-Mark, 20.10.2013
A-Mark, 21.10.2013
A-Mark, 22.10.2013
A-Mark, 23.10.2013
A-Mark, 24.10.2013
C-Mart, 19.01.2014
C-Mart, 20.01.2014
C-Mart, 21.01.2014
C-Mart, 22.01.2014
]

and the result is:

enter image description here

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top