Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have this warehouse database using MariaDB and want to show all stock for every item in every warehouse in Qliksense.
This is list_item_storage table to show relational from product to warehouse
storage_id | item_id | location_id |
1 | Product A | GBJ |
2 | Product A | FIN |
3 | Product B | GBJ |
4 | Product C | GBJ |
And this is list_item_tx table to show all in and out transaction related to every product in all warehouse.
tx_id | tx_date | storage_id | start_qty | change_qty | end_qty |
1 | 10/18/2018 12:48:23 | 1 | 0 | 2900 | 2900 |
2 | 11/8/2018 10:33:12 | 1 | 2900 | 2653 | 247 |
3 | 10/18/2018 12:48:56 | 3 | 0 | 1988 | 1988 |
4 | 11/8/2018 10:39:11 | 3 | 1988 | 198 | 1790 |
5 | 10/18/2018 12:48:27 | 4 | 0 | 280 | 280 |
6 | 11/8/2018 10:41:03 | 4 | 280 | 56 | 224 |
7 | 10/18/2018 12:48:02 | 2 | 0 | 0 | 0 |
I want to make something like below. But I can't get the right value to show the stock value. According to DB Admin, the logic is to grab all of the storage_id for every product in list_item_storage table. And then grab the storage_id with the latest date (tx_date) then show the end_qty in list_item_tx.
My problem is I can't get the right value for the latest stock for every product in every warehouse.
I tried several expression such as:
sum({<tx_date={"$(=max(tx_date))"}>}end_qty)
sum(if(tx_date=Max(tx_date),end_qty))
FirstSortedValue(if({<tx_date={"$(=max(tx_date))"}>}end_qty))
and even using Aggregation functions such as ONLY or MaxStrings and none of them succeed. Most of it ended with the result of showing NULL or showing only the last row value of the table.
Please help. Thanks in advance
Since there are item_name and location_name in the chart... I would rather use this
FirstSortedValue(Aggr(Sum(end_qty), item_name, location_name, tx_date), -Aggr(tx_date, item_name, location_name, tx_date))
Is that tx_date is the Date field? Try this way?
If(tx_date = Max(TOTAL tx_date), Sum(end_qty))
So, in your sample data... Product A have 2 different storage_ids.... do you want to pick the latest date across both storage_ids or do you want sum the latest value from each storage_id and display that?
Hi Sunny, I need to show latest date of end_qty for both storage_id. If there are 3 storage_id for a single product, it means the product are in 3 different storage and I need to show 3 of it individually.
May be try this...
FirstSortedValue(end_qty, -tx_date)
Hi Anil, yes, tx_date is Date field.
I've tried our suggestion and it shows NULL for all product
May be this?
FirstSortedValue(Aggr(Sum(end_qty), tx_date), -tx_date)
Since there are item_name and location_name in the chart... I would rather use this
FirstSortedValue(Aggr(Sum(end_qty), item_name, location_name, tx_date), -Aggr(tx_date, item_name, location_name, tx_date))
Hi Sunny,
Hi Anil,
I'm currently at home during weekend and unable to access the latest DB data to make sure if the expression fetch the data I need. I will try all of your suggestion on Monday and will get back to you all immediately. Thank you very much. Happy weekend.
Thanks Sunny. It's works like a charm. This is just what I need. BTW, what will be the difference if I'm using item_name & location_name and not using it in the expression. It seems that it return with same correct value whether I'm using it or not. I assume it will be more correct if I'm using it, but I'm not really sure what will happen if i'm not.