Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Is this possible through Set Analysis?

Hi everyone

I have the following data model where I have a list of Products sold and a field where it is indicated if a product was sold as result of a devolution from other:

ProductReturned Product#Packages
Product A1
Product AProduct B2
Product B5
Product B3
Product CProduct A7

I want to achieve the following result:

ProductSalesReturns
Product A37
Product B82
Product C70

Is this feasible through set analysis?

Many Thanks for your support.

1 Solution

Accepted Solutions
sunny_talwar

Check out the link table approach here

Table:

LOAD RowNo() as RowNum,

  *;

LOAD * INLINE [

    Product, Returned Product, #Packages

    Product A, Product B, 2

    Product A, , 1

    Product B, , 5

    Product B, , 3

    Product C, Product A, 7

];

LinkTable:

LOAD DISTINCT RowNum,

  Product as DimProduct,

  'Sales' as Flag

Resident Table

Where Len(Trim(Product)) > 0;

Concatenate (LinkTable)

LOAD DISTINCT RowNum,

  [Returned Product] as DimProduct,

  'Return' as Flag

Resident Table

Where Len(Trim([Returned Product])) > 0;

Dimension

DimProduct

Expressions

=Sum({<Flag = {'Sales'}>}#Packages)

=Sum({<Flag = {'Return'}>}#Packages)

Capture.PNG

View solution in original post

10 Replies
aarkay29
Specialist
Specialist

May be this

Return=sum({1<[Returned Product]=p(Product)>}#Packages)

Anonymous
Not applicable
Author

Hi Aar,

Thanks for your reply but that way results on a a new line, Product A, with 2 returns.

The objective is to have only the line with Product B.

sunny_talwar

May be like this

Dimension

Product

Expressions

=Sum({<[Returned Product] = {"=Len(Trim([Returned Product])) = 0"}>}#Packages)

=Sum(TOTAL {1<[Returned Product] = p(Product)>} #Packages)

Anonymous
Not applicable
Author

Hi Sunny,

Thanks for your reply. The issue here is when we have more that one Product with returns like I have put on your attached qvw. In this situations I will add all returned packages in all Products lines.

Please check the attached qvw

Many Thanks

sunny_talwar

But in your initial post you mentioned this:

"I want to achieve the following analysis when the user selects Product B"

I assumed that were going to be making a single selection in Product before you will see this. Is that not true anymore?

Anonymous
Not applicable
Author

That was just an example of the expected behaviour when the user selects Product B. But the user can perform any selection.

I will edit the initial post  and present the expected result wihout selections. Sorry if I was not clear

sunny_talwar

Don't have to be sorry my friend. Is modifying script a problem? If not, then try like this

Table:

LOAD *,

  If(Len(Trim([Returned Product])) = 0, Product, [Returned Product]) as DimProduct;

LOAD * INLINE [

    Product, Returned Product, #Packages

    Product A, Product B, 2

    Product A, , 1

    Product B, , 5

    Product B, , 3

    Product C, Product A, 7

];

Now use DimProduct as your dimension and two expressions

1) =Sum({<[Returned Product] = {"=Len(Trim([Returned Product])) = 0"}>}#Packages)

2) =Sum({<[Returned Product] = {"=Len(Trim([Returned Product])) > 0"}>}#Packages)

Anonymous
Not applicable
Author

But in that way we loose the sales of Product A where the Product B was returned (2 Packages) because the DimProduct on that record become Product B.

Check the first post for the desire result.

Many Thanks once again

sunny_talwar

Check out the link table approach here

Table:

LOAD RowNo() as RowNum,

  *;

LOAD * INLINE [

    Product, Returned Product, #Packages

    Product A, Product B, 2

    Product A, , 1

    Product B, , 5

    Product B, , 3

    Product C, Product A, 7

];

LinkTable:

LOAD DISTINCT RowNum,

  Product as DimProduct,

  'Sales' as Flag

Resident Table

Where Len(Trim(Product)) > 0;

Concatenate (LinkTable)

LOAD DISTINCT RowNum,

  [Returned Product] as DimProduct,

  'Return' as Flag

Resident Table

Where Len(Trim([Returned Product])) > 0;

Dimension

DimProduct

Expressions

=Sum({<Flag = {'Sales'}>}#Packages)

=Sum({<Flag = {'Return'}>}#Packages)

Capture.PNG