Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
libinanto95
Contributor
Contributor

For Loop Next

Main:
LOAD * INLINE [

Values, Month, Year,Material_code
1, Oct, 2018, 2000001
2, Nov, 2018, 2000001
1, Dec, 2018, 2000001
0, Jan, 2019, 2000001
0, Feb, 2019, 2000001
0, Mar, 2019, 2000001
0, Apr, 2019, 2000001
5, May, 2019, 2000001
0, Jun, 2019, 2000001
0, Jul, 2019, 2000001
6, Oct, 2018, 2000002
9, Nov, 2018, 2000002
4, Dec, 2018, 2000002
0, Jan, 2019, 2000002
0, Feb, 2019, 2000002
0, Mar, 2019, 2000002
7, Apr, 2019, 2000002
0, May, 2019, 2000002
2, Jun, 2019, 2000002
0, Jul, 2019, 2000002
];

 

This is Just an example of my requirement,

My requirement is :

Main:
LOAD * INLINE [

Values, Month, Year,Material_code
1, Oct, 2018, 2000001
2, Nov, 2018, 2000001
1, Dec, 2018, 2000001
1, Jan, 2019, 2000001
1, Feb, 2019, 2000001
1, Mar, 2019, 2000001
1, Apr, 2019, 2000001
5, May, 2019, 2000001
5, Jun, 2019, 2000001
5, Jul, 2019, 2000001
6, Oct, 2018, 2000002
9, Nov, 2018, 2000002
4, Dec, 2018, 2000002
4, Jan, 2019, 2000002
4, Feb, 2019, 2000002
4, Mar, 2019, 2000002
7, Apr, 2019, 2000002
7, May, 2019, 2000002
2, Jun, 2019, 2000002
2, Jul, 2019, 2000002
];

the Value of the Previous Month should be displayed in my next month value if only the Value is '0' by using For Loop Function..

 

Thanks and Regards,

 

2 Replies
sunny_talwar

Try this

Main:
LOAD *,
	 Date(MakeDate(Year, Month(Date#(Month, 'MMM'))), 'MMM-YYYY') as MonthYear;
LOAD * INLINE [
    Values, Month, Year, Material_code
    1, Oct, 2018, 2000001
    2, Nov, 2018, 2000001
    1, Dec, 2018, 2000001
    0, Jan, 2019, 2000001
    0, Feb, 2019, 2000001
    0, Mar, 2019, 2000001
    0, Apr, 2019, 2000001
    5, May, 2019, 2000001
    0, Jun, 2019, 2000001
    0, Jul, 2019, 2000001
    6, Oct, 2018, 2000002
    9, Nov, 2018, 2000002
    4, Dec, 2018, 2000002
    0, Jan, 2019, 2000002
    0, Feb, 2019, 2000002
    0, Mar, 2019, 2000002
    7, Apr, 2019, 2000002
    0, May, 2019, 2000002
    2, Jun, 2019, 2000002
    0, Jul, 2019, 2000002
];

FinalTable:
NoConcatenate
LOAD Material_code,
	 MonthYear,
	 Month,
	 Year,
	 If(Material_code = Previous(Material_code), If(Values = 0, Peek('Values'), Values), Values) as Values
Resident Main
Order By Material_code, MonthYear;

DROP Table Main;
Brett_Bleess
Former Employee
Former Employee

Anto, did Sunny's post help you resolve your use case?  If so, please consider using the Accept as Solution button on his post to let others know this worked for you.  If you still need help, provide an update on things, so others can see if they can help.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.