Skip to main content
Announcements
The way to achieve your own success is the willingness to help somebody else. Go for it!
cancel
Showing results for 
Search instead for 
Did you mean: 
thanhphongle
Creator II
Creator II

Interval Match Start and Stop Date to Calender

Hello Community,

 

I have a marketing campaign which has a start and a stop date.

 

I want to join the period (date between start and stop) to my calender.

Example:

 

Marketing_Table:

ChannelArticle_IDStartStopPrice
NewsletterA30.01.201931.01.2019600
NewsletterA01.02.201905.02.2019500
FlyerA03.02.201906.02.2019400

 

Calender:

Date
30.01.2019
31.01.2019
01.02.2019
02.02.2019
03.02.2019
04.02.2019
05.02.2019
06.02.2019

 

Goal Result:

CalendarChannelArticle_IDStartStopPrice
30.01.2019NewsletterA30.01.201931.01.2019600
31.01.2019NewsletterA30.01.201931.01.2019600
01.02.2019NewsletterA01.02.201905.02.2019500
02.02.2019NewsletterA01.02.201905.02.2019500
03.02.2019NewsletterA01.02.201905.02.2019500
03.02.2019FlyerA03.02.201906.02.2019400
04.02.2019NewsletterA01.02.201905.02.2019500
04.02.2019FlyerA03.02.201906.02.2019400
05.02.2019NewsletterA01.02.201905.02.2019500
05.02.2019FlyerA03.02.201906.02.2019400
06.02.2019FlyerA03.02.201906.02.2019400

 

I heard about the IntervalMatch Function, but I dont really know how to use it.

Maybe anyone could help me out here?

Thx.

 

Labels (1)
1 Solution

Accepted Solutions
Arthur_Fong
Partner - Specialist III
Partner - Specialist III

Try this:


Calender:
load Date#(Date,'DD.MM.YYYY')AS Date inline [
Date
30.01.2019
31.01.2019
01.02.2019
02.02.2019
03.02.2019
04.02.2019
05.02.2019
06.02.2019
];

Marketing_Table:
load Channel,Article_ID,Price,Date#(Start,'DD.MM.YYYY') as Start,Date#(Stop,'DD.MM.YYYY')as Stop inline [
Channel,Article_ID,Start,Stop,Price
Newsletter,A,30.01.2019,31.01.2019,600
Newsletter,A,01.02.2019,05.02.2019,500
Flyer,A,03.02.2019,06.02.2019,400
];
inner join
IntervalMatch(Date)
load Start,Stop resident Marketing_Table;

 


exit SCRIPT;

View solution in original post

3 Replies
Arthur_Fong
Partner - Specialist III
Partner - Specialist III

Try this:


Calender:
load Date#(Date,'DD.MM.YYYY')AS Date inline [
Date
30.01.2019
31.01.2019
01.02.2019
02.02.2019
03.02.2019
04.02.2019
05.02.2019
06.02.2019
];

Marketing_Table:
load Channel,Article_ID,Price,Date#(Start,'DD.MM.YYYY') as Start,Date#(Stop,'DD.MM.YYYY')as Stop inline [
Channel,Article_ID,Start,Stop,Price
Newsletter,A,30.01.2019,31.01.2019,600
Newsletter,A,01.02.2019,05.02.2019,500
Flyer,A,03.02.2019,06.02.2019,400
];
inner join
IntervalMatch(Date)
load Start,Stop resident Marketing_Table;

 


exit SCRIPT;

Stoyan_Terziev
Partner - Creator III
Partner - Creator III

Hello,

I saw Arthur already explained how IntervalMatch works.

I suspect you are looking for the function IterNo() instead of Interval match.

This will generate your table automatically regardless of any calendar ranges:

	Marketing_Table:
	LOAD
		Channel
	, 	Article_ID
	, 	Num(Date#(Start, 'DD.MM.YYYY')) AS Start
	, 	Num(Date#(Stop, 'DD.MM.YYYY')) AS Stop
	, 	Price
	,	RowNo() as Marketing_TableID
	;
	LOAD * INLINE [
	    Channel, Article_ID, Start, Stop, Price
	    Newsletter, A, 30.01.2019, 31.01.2019, 600
	    Newsletter, A, 01.02.2019, 05.02.2019, 500
	    Flyer, A, 03.02.2019, 06.02.2019, 400
	];


For i=0 to NoOfRows('Marketing_Table')-1

	LET vEachRowCalID		= peek('Marketing_TableID', $(i), 'Marketing_Table');
	LET vEachRowCalStart	= peek('Start', $(i), 'Marketing_Table');
	LET vEachRowCalEnd		= peek('Stop', $(i), 'Marketing_Table');
	
	Calendar:
	LOAD 
	'$(vEachRowCalID)' as Marketing_TableID,
	Date( Start + IterNo() - 1 ,'DD.MM.YYYY') as Calendar
	While Start + IterNo() - 1 <= Stop
	;
	LOAD 
	Start, Stop
	RESIDENT Marketing_Table
	WHERE Marketing_TableID='$(vEachRowCalID)'
	;
	
	Trace i;
	

NEXT i;


LEFT JOIN(Marketing_Table)
LOAD 
Marketing_TableID,
Calendar
RESIDENT Calendar;

DROP TABLE Calendar;

 

I hope that helps!

 

Kind regards,

S.T.

thanhphongle
Creator II
Creator II
Author

Hello together,

 

thank you for giving me a quick answer.

 

The solution with the intervalmatch works fine for me.

Of course the other solutions are welcome.

 

Thank you

Best regards  Le