Expression analysis in textbox qlikview - qlikview

I have data like this in a sheet:
products obtained total
p1 1200 10000
p2 1000 20000
p3 200 30000
p1 1400 10000
p2 1200 20000
p3 600 30000
If I get the sum of products then p1 shows 2400 p2=2400 and p3=800
So I get 2400 top value against twp products ..
I want to get top values in textbox like this:
p1 (2400/10000) p2 (2400/20000)
How do I do this?

example for p1:
='p1 ('&sum({<products={'p1'}>} obtained)&'/'&only{<products={'p1'}>} total)&')'
might want to use avg instead of only if the total can change

Related

SQL Query - Conditional Rolling Subtraction and Association

Firstly I'll lay out my data in its simplified form to demonstrate what I'm dealing with:
Stock Table:
Component
Quantity
Batch
Expiry Date
Brick
1500
B1
12/05/2023
Brick
1500
B2
30/05/2023
Brick
1500
B3
22/06/2023
Steel
2500
S1
12/05/2023
Steel
2500
S2
18/05/2023
Glass
15000
G1
29/09/2023
Glass
15000
G2
12/12/2023
Builds Table:
Build ID
Req Component
Req Quantity
Req Date
1
Steel
5000
01/01/2023
1
Brick
4000
02/01/2023
1
Glass
10000
03/01/2023
2
Steel
5000
15/01/2023
2
Brick
4000
16/01/2023
2
Glass
10000
17/01/2023
What you see above is a table of stuck and the batches of said stock and their respective quantities. The next table is a list of upcoming builds and their material requirement.
Based on what I'm trying to achieve I would expect to see the following as the output.
Build ID
Component
Req Quantity
Req Date
Assigned Batch
Rmn Qty(batch)
1
Steel
5000
01/01/2023
S1
2500
1
Steel
2500
01/01/2023
S2
0
1
Brick
4000
02/01/2023
B1
0
1
Brick
2500
02/01/2023
B2
0
1
Brick
1000
02/01/2023
B3
500
1
Glass
10000
03/01/2023
G1
5000
2
Steel
5000
15/01/2023
NO STOCK
2
Brick
4000
16/01/2023
B3
0
2
Brick
3500
16/01/2023
NO STOCK
2
Glass
10000
17/01/2023
G1
0
2
Glass
5000
17/01/2023
G2
10000
The stock is automatically assigned and distributed against the orders based on the required date and the expiry date - the rolling subtraction occurs that a batch may not be fully consumed on a given build and as such can be used again later.
If any more information is required please let me know.

sum tabel based on certain content

select
om.orderno,
od.product,
od.preorderqty,
(od.preorderqty * od.nto) as preordernet
from OrderMaster om
join OrderDetail od on od.orderid = om.id
and ((od.prodcode like '100-%') or (od.prodcode like '200-%'))
order by om.orderno,sod.prodcode
Current result:
ORDERNO PRODUCT PREORDERQTY PREORDERNET
1000 100-A 2 200
1000 100-B 2 300
1000 100-C 1 450
2000 100-A 3 300
2000 100-B 1 150
2000 200-A 2 900
3000 200-A 1 450
I would need help getting a script that:
Sums the orders based on specific content
Orders can contain products beginning with 300- etc.
Expected result:
ORDERNO PRODUCT PREORDERQTY PREORDERNET ORDERNET
1000 100-A 2 200 950
1000 100-B 2 300 950
1000 100-C 1 450 950
2000 100-A 3 300 1350
2000 100-B 1 150 1350
2000 200-A 2 900 1350
3000 200-A 1 450 450
As I understood from the expected output ,use sum as window function to get it,
select om.orderno
,od.product
,od.preorderqty
,(od.preorderqty * od.nto) as preordernet
,sum(od.preorderqty * od.nto) over (partition by om.orderno) as ordernet
from OrderMaster om
join OrderDetail od
on od.orderid = om.id
and ((od.prodcode like '100-%')
or (od.prodcode like '200-%'))
order by om.orderno,sod.prodcode

sum revenue based on criteria form another table Powerpivot

I have a model where I have Revenue table that has revenue2016 column
another table Programs where i have
program | min
I would like to add a calculated column to programs table so that it sums revenue that is grater than the min like so
=CALCULATE(SUM(Revenue[revenue2016 ]),Revenue[revenue2016]>=Programs[min])
this gave me an error
The data should look like this
#Revenue
Revenue
10
10
10
10
10
100
100
100
100
100
1000
1000
1000
1000
1000
#Programs
program | min | summed rev
a | 10 | 5550
b | 100 | 5500
c | 1000 | 5000
Just After I posted it I found the answer, I'll share it if someone else came across same issue
=calculate(sum(Revenue[revenue2016]),filter(Revenue,Revenue[revenue2016]>=Programs[Min]))

Access the previous row in select

I have a scenario as below
--source data
departuredttm flight_source flight_destination available_seats
13-07-2016 04:00:00 A B 200
13-07-2016 08:00:00 A B 320
13-07-2016 08:20:00 A B 20
I have a lookup table which tell how many total passengers are there for this source and destinatin whose flights are delayed and needs to adjusted in available seats in source data.lookup table is like this.
--lookup table for passenger_from_delayed_flights
flight_source flight_destination passengers
A B 500
now I have to adjust these 500 passengers in available seats as in source data
---output
DepartureDttm flight_source flight_destination AVAILABLE_SEATS PASSENGERS_TO_ADJUST PASSENGER_LEFT
13-07-2016 04:00:00 A B 200 500 300
13-07-2016 08:00:00 A B 320 300 20
13-07-2016 08:20:00 A B 20 20 0
initially passenger to adjust is 500 where we have 200 seats , next 320 seats are available and we have to adjust 300 (500-200) passengers.
Please help
Thanks
Your expected result is probably wrong, the 2nd flight already has enough seats, so PASSENGER_LEFT should be -20 (or 0).
This is a calculation based on a running total:
passengers - SUM(available_seats)
OVER (ORDER BY departuredttm
ROWS UNBOUNDED PRECEDING) AS PASSENGER_LEFT
available_seats + PASSENGER_LEFT AS PASSENGERS_TO_ADJUST

Sum values from Duplicated rows

There's my sql data:
code name total
---------------
3 Sprite 2400
17 Coke 1500
6 Dew 1000
17 Coke 3000
6 Dew 2000
But code and name has duplicated values and I want to sum total from each duplicated field.
Something like this:
code name total
---------------
3 Sprite 2400
17 Coke 4500
6 Dew 3000
How could I do that in sql?
SELECT code, name, sum(total) AS total FROM table GROUP BY code, name