Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
daniel_kusiak
Creator II
Creator II

Spliting part of data based on %value

Hi Community,

Let's say that my data model looks like this:

Prim ClassSec Class DescriptionRefNoValueWskValue*Wsk
11Desc 1111100100%100
11Desc 1222100100%100
11Desc 1333100100%100
22Desc 2444100100%100
22Desc 2555100100%100
22Desc 2666100100%100
12Desc 277710050%50

Please notice that last position RefNo 777 has Wsk=50%. Now, what i want to do is to return missing 50% to it's primary class, so the results look like this:

Prim ClassSec ClassDescriptionRefNoValueWskValue*Wsk
11Desc 1111100100%100
11Desc 1222100100%

100

11Desc 1333100100%100
11Desc 177750100%50
22Desc 2444100100%100
22Desc 2555100100%100
22Desc 2666100100%100
12Desc 277750100%50

Now, please notice that position RefNo 777 now exist in Sec Class 1 and 2.

Is there any way to achive this?

Best regards

Daniel

1 Solution

Accepted Solutions
effinty2112
Master
Master

Hi Daniel,

          Try this script

Source:

LOAD [Prim Class],

     [Sec Class],

     Description,

     RefNo,

     Value,

     Wsk,

     [Value*Wsk]

FROM

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

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

NoConcatenate

OK:

Load * Resident Source Where Wsk  = 1;

NoConcatenate

NotSoGood:

Load * Resident Source Where Wsk  <> 1;

NoConcatenate

ToBeAppendedToOK:

Load

[Prim Class],

     [Sec Class],

     Description,

     RefNo,

     Value * Wsk as Value,

     1 as Wsk,

      [Value*Wsk]

Resident NotSoGood;

Load

[Prim Class],

    1 as [Sec Class],

     'Desc 1'  as Description,

     RefNo,

     Value * (1-Wsk) as Value,

     1 as Wsk,

      [Value*Wsk]

Resident NotSoGood;

Drop Tables Source, NotSoGood;

Concatenate(OK)

LOAD * Resident ToBeAppendedToOK;

DROP Table ToBeAppendedToOK;

Cheers

Andrew

View solution in original post

5 Replies
antoniotiman
Master III
Master III

Hi Daniel,

what if

Sec Class 1  100%

Sec Class 2  100%

Sec Class 3    50%

Sec Class 4    25%

........

daniel_kusiak
Creator II
Creator II
Author

Unfortunately i can't use this solution. The RefNo 777 must be splited between SecClass 1 and 2 based on %value of Wsk.

effinty2112
Master
Master

Hi Daniel,

          Try this script

Source:

LOAD [Prim Class],

     [Sec Class],

     Description,

     RefNo,

     Value,

     Wsk,

     [Value*Wsk]

FROM

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

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

NoConcatenate

OK:

Load * Resident Source Where Wsk  = 1;

NoConcatenate

NotSoGood:

Load * Resident Source Where Wsk  <> 1;

NoConcatenate

ToBeAppendedToOK:

Load

[Prim Class],

     [Sec Class],

     Description,

     RefNo,

     Value * Wsk as Value,

     1 as Wsk,

      [Value*Wsk]

Resident NotSoGood;

Load

[Prim Class],

    1 as [Sec Class],

     'Desc 1'  as Description,

     RefNo,

     Value * (1-Wsk) as Value,

     1 as Wsk,

      [Value*Wsk]

Resident NotSoGood;

Drop Tables Source, NotSoGood;

Concatenate(OK)

LOAD * Resident ToBeAppendedToOK;

DROP Table ToBeAppendedToOK;

Cheers

Andrew

daniel_kusiak
Creator II
Creator II
Author

Nice one 🙂 If we ever meet in person i'll buy you a beer.

Thank you.

effinty2112
Master
Master

Hi Daniel,

I'll hold you to that!!!

Andrew