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: 
Not applicable

Multiply two fields on script

Hi all,

I want to multiply fields on script but I need help.

This is what I have:

    

PaísID_DatoTIPO_TIP% POR TIPO
AlemaniaCOR.001DEF90,0000%
AlemaniaCOR.001KEY95,0000%
SpainCOR.002DEF99,0000%
SpainCOR.002KEY98,0000%
SpainCOR.002DOC40,0000%

I want to have the result at ID_Dato level, like this:

   

PaísID_Dato% DATO
AlemaniaCOR.00185,5000%
SpainCOR.00238,8080%

I have to multiply them (COR.001 = 85,500% = 90,00%*95,00% and COR.002 = 38,808% = 99,00%*98,00%*40,00%).

I tried SUM, ONLY, AVG.. and I didn't get anything.

Thank you.

1 Solution

Accepted Solutions
sinanozdemir
Specialist III
Specialist III

Way easier answer by using some Math functions:

Capture.PNG

And here is the data model:

Capture.PNG

Use of Log(), Exp() and Sum() functions.

Hope this helps.

View solution in original post

8 Replies
crystles
Partner - Creator III
Partner - Creator III

Which fields are you trying to multiply?

You would have to make a distinction between the two COR fields, by the TIPO_TIP field I am assuming. Maybe that is why it isn't working?

Could you post your script code?

raajaswin
Creator III
Creator III

Try AGGR function to group things.

Hope it will work

sunny_talwar

This?

Capture.PNG

Script:

Table:

LOAD País,

    ID_Dato,

    TIPO_TIP,

    SubField([% POR TIPO], ',', 1)/100 as [% POR TIPO]

FROM

[https://community.qlik.com/thread/187022]

(html, codepage is 1252, embedded labels, table is @1);

Join(Table)

LOAD País,

    ID_Dato,

    Evaluate(Concat([% POR TIPO], '*')) as NewField

Resident Table

Group By País, ID_Dato;

raajaswin
Creator III
Creator III

=aggr((Exp(Sum(Log(%POR TIPO)))),ID_Dato)

maxgro
MVP
MVP

SET ThousandSep=".";

SET DecimalSep=",";

Z:

LOAD   rowno() as id,  País, ID_Dato,  TIPO_TIP,

    ((replace([% POR TIPO], '%', ''))+0)/100 as Field

FROM

[https://community.qlik.com/thread/187022]

(html, codepage is 1252, embedded labels, table is @1);

Y:

NoConcatenate

load  id, País,  ID_Dato, TIPO_TIP,

    if(País=Peek(País) and ID_Dato=peek(ID_Dato), peek(Result)*Field, Field) as Result

Resident Z

order by País, ID_Dato, id;

DROP Table Z;

T:

NoConcatenate

load * Resident Y

Where not (País=Peek(País) and ID_Dato=peek(ID_Dato))

Order by id desc;

DROP Table Y;

1.png

sinanozdemir
Specialist III
Specialist III

Way easier answer by using some Math functions:

Capture.PNG

And here is the data model:

Capture.PNG

Use of Log(), Exp() and Sum() functions.

Hope this helps.

Not applicable
Author

You saved my life!

sinanozdemir
Specialist III
Specialist III

You are welcome

One of my coworkers is a Math genius.