Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
nickleshkevich
Contributor II
Contributor II

Balance availability factor

Hi guys!

I have the following table:

DateMaterialBalance

Shipments

BAF

01.05.18

20000518

13 615,000,0012,53

02.05.18

20000518

13 615,00135,0011,53
03.05.18

20000518

13 480,002 155,00...
04.05.18

20000518

11 325,001 790,00...
05.05.18

20000518

9 535,000,00
06.05.18

20000518

9 535,001 080,00
07.05.18

20000518

8 455,00160,00
08.05.18

20000518

8 455,0060,00
09.05.18

20000518

10 620,00150,00
10.05.18

20000518

10 470,002 370,00
11.05.18

20000518

8 100,004 015,00
12.05.18

20000518

5 586,0050,00
13.05.18200005188 595,003 120,00

For each day and material, I need to calculate balance availability factor

For example for the first date (01.05.2018) it'll be:
Balance (01.05.2018 = 13 615,00) - Shipments (01.05.2018 = 0,00) - Shipments (02.05.2018 = 135,00) - .. - Shipments( i ), until result will not be negative. Something like that:

Balance*ShipmentsResultFlag

13 615,00

0,0013 615,001

13 615,00

135,0013 480,001
13 480,002 155,0011 325,001
11 325,001 790,009 535,001
9 535,000,009 535,001
9 535,001 080,008 455,001
8 455,00160,008 295,001
8 295,0060,008 235,001
8 235,00150,008 085,001
8 085,002 370,005 715,001
5 715,004 015,001 700,001
1 700,0050,001 650,001
1 650,003 120,00- 1 470,000

BAF(balance availability factor) = Sum(Flag) + last_value(in our case it's = 1 650,00) / Appropriate value of Shipments (3 120,00)

BAF = 12 + 0,53 = 12,53

Could you help me, please?

Thank you very much!

5 Replies
Anonymous
Not applicable

Hi,

To get to the second table you showed, you can use it:

Data:

Load * Inline

[

Date, Material, Balance, Shipments

01/05/2018, 20000518, 13615, 0

02/05/2018, 20000518, 13615, 135

03/05/2018, 20000518, 13480, 2155

04/05/2018, 20000518, 11325, 1790

05/05/2018, 20000518, 9535, 0

06/05/2018, 20000518, 9535, 1080

07/05/2018, 20000518, 8455, 160

08/05/2018, 20000518, 8455, 60

09/05/2018, 20000518, 10620, 150

10/05/2018, 20000518, 10470, 2370

11/05/2018, 20000518, 8100, 4015

12/05/2018, 20000518, 5586, 50

13/05/2018, 20000518, 8595, 3120

];

FinalData:

Load If(RowNo()<3, Balance, peek(Balance) - peek(Shipments)) As Balance,

          Shipments,

          If(RowNo()=1, Balance, peek(Result) - Shipments) As Result,

          If(If(RowNo()=1, Balance, peek(Result) - Shipments) > 0, 1, 0) As Flag

Resident Data

Order by Date;

Drop Table Data;

I am not sure how I am suposed to calculate BAF. There shoud be one BAF for each row? How did you get to the value "11,53" on the second record of your first table?

nickleshkevich
Contributor II
Contributor II
Author

Hi, thank you for your answer,
I guess, I didn't explain it right, I'll try again.
I have the table with fields Material, Date and calculated fields Balance, Shipments. For each Material and Date, I need to calculate also BAF, which calculate depends on the values in the future period.
For example:
BAF from my previous for Material = '20000518' and Date = '01.05.2018' will be calculated like this:

Step 1

Balance(01.05.2018) - Shipments(01.05.2018) = 13615.00 - 0.00 = 13615.00 (Result 1), then I need to check is this value positive, if so, then BAF = BAF + 1, next step
Step 2

Balance for evening (01.05.2018) - Shipments(02.05.2018) = 13615.00 - 135.00 = 13480.00 (Result 2), is this value positive? if so,  BAF = BAF + 1, next step

......

Do it until Balance positive

last step 13

We have Result 12 which is 1650.00 and  Shipments for this step is 3120.00, it's greater than our Result 12, so for this step, BAF will be calculated by another formula:

BAF = BAF + Result 12 / Shipments (13.05.2018) = 12 + 1650.00 / 3120.00 = 12.53

If I could write an algorithm, it would be something like this:

BAF = 0;

Res = Balance (01.05.2018);

While Res > 0 do

     if(Res - Ship[BAF] > 0)

          BAF = BAF +1;

          Res = Res - Ship[BAF];       

     else

          BAF = BAF + Res / Ship[BAF + 1]

          Res = Res - Ship[BAF + 1];

End While

I had an idea to do it with
RangeSum( Below( Sum(Shipments), 0, i) )

but I don't know how to calculate i in frontend(table) expressions

Anonymous
Not applicable

Hello again, Nikolay!

With this script ...

Data:

Load * Inline

[

Date, Material, Balance, Shipments

01/05/2018, 20000518, 13615, 0

02/05/2018, 20000518, 13615, 135

03/05/2018, 20000518, 13480, 2155

04/05/2018, 20000518, 11325, 1790

05/05/2018, 20000518, 9535, 0

06/05/2018, 20000518, 9535, 1080

07/05/2018, 20000518, 8455, 160

08/05/2018, 20000518, 8455, 60

09/05/2018, 20000518, 10620, 150

10/05/2018, 20000518, 10470, 2370

11/05/2018, 20000518, 8100, 4015

12/05/2018, 20000518, 5586, 50

13/05/2018, 20000518, 8595, 3120

];

TmpData:

NoConcatenate

Load Date,

     Material,

     If(RowNo()<3, Balance, peek(Balance) - peek(Shipments)) As Balance,

     Shipments,

     If(RowNo()=1, Balance, peek(Result) - Shipments) As Result,

     If(If(RowNo()=1, Balance, peek(Result) - Shipments) > 0, 1, 0) As Flag

Resident Data

Order by Date;

Tmp:

Load Sum(Flag) As Factor

Resident TmpData

Group By Flag

Order By Flag Desc;

Let vSumFlag = Peek('Factor', 0, 'Tmp');

Let vFactor = Round(Peek('Balance', $(vSumFlag), 'TmpData') / Peek('Shipments', $(vSumFlag), 'TmpData'), 0.01);

Let vFirstBAF = vSumFlag + vFactor;

FinalData:

Load Date,

     Material,

     Balance,

     Shipments,

     If(Num#('$(vFirstBAF)') - RowNo() + 1 > 0, Num#('$(vFirstBAF)') - RowNo() + 1, 0) As BAF

Resident TmpData;

Drop Table Data, Tmp, TmpData;

...I end up with this table:

Capturar.PNG

Is this the result you are expecting?

nickleshkevich
Contributor II
Contributor II
Author

Hello, Daniel, thank you for the answer!

Unfortunately, this is not suitable for me(

I attached a piece of data for an example and Excel doc with correct values.

Thank you very much for your desire to help!

nickleshkevich
Contributor II
Contributor II
Author

Need help!