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

writing to table within loop

Hello,

Trying to create a table which is a result of reading two other resident tables, and a lot of conditional inline logic

(greatly simplified logic here)

[TABLE_A]

Field_1

Field_2

[TABLE_B]

Field_3

Field_4

For each Field_1

               if condition is satisfied

                    Let x = Field_2 * Field_3

                     ??? how do I now write x to TABLE_C ? ???

               end if

Next

Question: how to write to create TABLE_C ?

any guidance would be appreciated!

11 Replies
Clever_Anjos
Employee
Employee

It would be easier if you could elaborate more your question, maybe posting some real (fake) data.

There´s some features like LOAD AUTOGENERATE, or LOAD WHILE that could help you

Clever_Anjos
Employee
Employee

Useful reading : Loops in the Script

MarcoWedel

You should try to describe the data and expected result instead of the solution you have in mind.

Loops of this kind imo should be the last solution to look for.

Hope this helps

Regards

Marco

Not applicable
Author

Thanks, I have read this; all the examples seem focused on reading lists of files. I am more intrested in WRITING new tables based on resident tables.

Clever_Anjos
Employee
Employee

Please tell us more about your need, maybe placing some excel files with inputs and results

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Replace the "??? how do I now write x to TABLE_C ? ???" line with something like:

TABLE_C:

LOAD x, somemorestuff, evenmorethings

AUTOGENERATE 1;

Each statement will AUTOCONCATENATE a row to the other rows. Of course, the first LOAD will create the table structure..

But as Marco said, loops aren't always the best constructs to obtain a specific result. They are very slow and there may be more elegant solutions available.

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try like this

TableA:

LOAD

Field_1

Field_2

FROM TableA;

TableB:

LOAD

Field_3

Field_4

FROM TableB;

TempTableC:

NoConcatenate

LOAD

*

RESIDENT TableA;

LEFT JOIN(TempTableC)

LOAD

*

RESIDENT TableB;

TableC:

LOAD

*

WHERE Flag = 1;

LOAD

Field_1,

Field_2 * Field_3 AS x,

If(Some Condition, 1, 0) AS Flag

RESIDENT TempTableC;

Hope this helps you.

Regards,

Jagan.

Not applicable
Author

Hello all, and thanks for the input thus far. I think the advise from clever and marco is valid ("tell me what you are trying to do").

I am trying to identify stock that will hit its expiry date before it is cosumed (based on forecasted sales). If it does expire before being consumed, need to know the qty that is not sellable.

here is a qvw that I mocked up, I beleive it has all the info

required.

SKUs have a forecast assigned to them. Batches are unique to a SKU. Bataches are consumed FEFO.

any assistance / guidance would be most appreciated!

Not applicable
Author

Hi Marco, I have posted it below.