Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
mcemerden
Contributor
Contributor

Filter on group and display all rows if at least one row matches filter on filter pane.

Hi everyone. So I've been working on Qlik pretty recently. I've got a question that I couldn't figure out myself for hours. 

So I have two tables regarding grocery store transactions.  One table (Transactions) has one row per each transaction and lists information on each transaction such as TransactionID (Key), Date, amount spent, payment method etc. 

The other table (Items) has a row for every single item involved in a transaction. It involves information like, TransactionID (Key), Price, Category,  Description, which aisle the product is in etc. So if someone goes in the grocery store and buys 5 items, there will be 5 rows in the Items table whereas there will only be one row in the Transactions table. 

I want to filter the items table grouped by Transaction ID. So for example, if I want to filter for "Home Goods" among category, the items table will only return all rows that have the value "Home Goods" in the Category column. However, the result I want is returning every item in all transactions that involve at least one "Home Goods" item. 

For example, Transactions and Items tables below:

TransactionIDTransactionDateAmountSpent
00109.27.202172
00209.27.2021150
00309.26.202140

 

TransactionIDCategoryPrice
001Home Goods35
001Frozen12
001Hygiene25
002Outdoors150
003Fresh10
003Home Goods15
003Alcohol15

 

 

So let's say I put a filter pane with Dimension "Category". Then I select, "Home Goods". Applying this filter to both tables gives me:

TransactionIDTransactionDateAmountSpent
00109.27.202172
00309.26.202140

 

Which is what I want from the Transactions table. However this is what I get from the Items table:

TransactionIDCategoryPrice
001Home Goods35
003Home Goods15

 

What I actually want is a table that contains all items from transaction 001 because it included a product from that category. The output I want looks like this:

TransactionIDCategoryPrice
001Home Goods35
001Frozen12
001Hygiene25
003Fresh10
003Home Goods15
003Alcohol15

 

Is there a way I can achieve this by using a different expression on the filter pane? Thank you!

5 Replies
Vegar
MVP
MVP

mcemerden
Contributor
Contributor
Author

I'll check them out now

anthonyj
Creator III
Creator III

Hi @mcemerden ,

I've been looking at this problem using the possible functions but I've been coming up against the fact that if you choose a category from the column then it will automatically filter out the other categories. I've played with alternate states but haven't been able to get that to work either. I'm sure someone more adept than I can figure that out but in the mean time I worked it out by altering the model.

By adding another table with TransactionID and a Category you can select a Category (Home Goods) and because it is associating through the TransactionID the table will show all Categories associated with that selected Category.

anthonyj_0-1632877245396.pnganthonyj_1-1632877315041.png

I hope this helps.

Thanks

Anthony

Vegar
MVP
MVP

@mcemerden 

Vegar_0-1632898771378.png

Using the expression below will enable you to get the prices for all transactions for  orders containing any of the selected categories, like in the image above.

=only({$<TransactionID=P(TransactionID), Category>}Price)

 

anthonyj
Creator III
Creator III

Great response @Vegar . I tried something similar with the "Only" and P( ) but was slightly off with the logic. I'll file that away for use in the future.

Thanks

Anthony