Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
nevilledhamsiri
Specialist
Specialist

Linking two tables & achieve the expected output

Dear Experts!

Please refer two excel tables which I need to link & create a table  like the 3rd one to show a simple  profit/loss calculation. Of course the two months revenue & commissions to be converted to running average & to take the latest month running average (Aug) & to be taken to the 3rd table. The figures  in 1st table to be taken as it is.


Thanks in advance


Neville

1st Table

BRANCH     GROSS_PREMIUM      CLAIMS     EXPENSES

RA               2,000,000                     450,000     400000

EH               1,500,000                     500,000     350000

K7               1,700,000                     650,000     250000

K9               1,500,000                     700,000     350000

2nd Table

BRANCH    MONTH    REVENUE    COMMISSION

RA              JUL         2000000         250000

RA              AUG         2200000         350000

EH              JUL         1500000         400000

EH              AUG         1700000         350000

K7              JUL         900000         200000

K9              JUL         750000         150000

K9              AUG         700000         250000

Output should look like below:

BRANCH    GROSS_PREMIUM    RUNNING_REVENUE    RUNNING_COMMISSION    ACTUAL CLAIMS    ACTUAL EXPENSES    PROFIT/LOSS

RA               2,000,000               2100000                       300000                                 450,000     400000                                  950,000

EH               1,500,000               1600000                       375000                                     500,000     350000                             375,000

K7               1,700,000               950000                       225000                                      650,000     250000                             (175,000)

K9                   1,500,000               725000                       200000                                 700,000     350000                             (525,000)

1 Solution

Accepted Solutions
nevilledhamsiri
Specialist
Specialist
Author

This is true!, I have just said as it is appeared in your working of course it has to be

   2,040,743

How did you derive the value of 2654689 for BL?

Sorry

View solution in original post

18 Replies
oscar_ortiz
Partner - Specialist
Partner - Specialist

Neville,

Please look at attached, on my way to the airport so no time to add a description of what I'm doing here.

276418.PNG

I believe this is what you're looking for.

Good luck!

Oscar

nevilledhamsiri
Specialist
Specialist
Author

Dear Oscar,

That is what I need. Will you please show me how you link the tables & expression used thereafter!

Thanks

Neville

oscar_ortiz
Partner - Specialist
Partner - Specialist

Neville,

I did not change anything as far as the script goes.  The two tables are automatically associated by the common BRANCH column.

For the chart I used the BRANCH as my dimension and the following for expressions:

Gross Premium = Sum(GROSS_PREMIUM)

Running Revenue = Avg(REVENUE)

Running Commission = Avg(COMMISSION)

Actual Claims = Avg(CLAIMS)

Actual Expenses = Avg(EXPENSES)

P&L = [Running Revenue] - ([Running Commission] + [Actual Claims] + [Actual Expenses])

Good luck

Oscar

nevilledhamsiri
Specialist
Specialist
Author

Dear Oscar,

Thanks a lot for your quick response!

That was OK. Also, if I applied 1st expression given below to find running average , how it will be fitted to this. Also how that expression be brought in to table. If you dont mind please look in to that. The 2nd expression I wrote to bring in latest running value which in August but an error comes!

Thanks in advance

Neville

RangeAvg(ABOVE(RangeSum(REVENUE),0,RowNo()))

sum({<BRANCH={'RA','EH','K7','K9'},MONTH={'AUG'}>}RangeAvg(ABOVE(RangeSum(REVENUE),0,RowNo()))

nevilledhamsiri
Specialist
Specialist
Author

Dear Oscar,Wishwanath or any other Dear ones,

Oscar of course helped me to get my job done. But some parts that is running through my mind needs to get corrected!

As I have stated above, Monthly Revenue & other variables are given & to be linked to p&l simple format. As Mr Oscar said (avg) function worked. But If I am to use the running latest month value to be considered at the P&l summery. How it could be done. This will be very much the case when it comes to 3rd Month & so on. (If is is 3rd Month I need to pick the latest 3rd Month Value as the running average. Please look in to this.

Rgds

Neville

oscar_ortiz
Partner - Specialist
Partner - Specialist

Neville,

I'm sorry but I don't understand exactly what you are looking for.  Could you provide an example of your need based on the data you provided what would your expected results look like?

Thanks

Oscar

nevilledhamsiri
Specialist
Specialist
Author

Dear oscar,

There are two table as below. 1st one carries Monthly Revenue , commissions & their running averages. 2nd table is for the calculation of profit/loss from part of  data taken from 1st table & balance from other tables. You had taken the average using (AVG) function earlier that was when it was only for two Months. But when its is more Months, I need to consider the latest running revenue & commission as per data given below Rs 268750 a revenue & Rs 23125 as commissions!. Please propose an expression to take the latest Month Average figure!

Thanks

Neville

  

TABLE_A
MONTHREVENUERUNN_AVERAGE_REVENUECOMMISSIONRUNN_AVERAGE_COMMISSION
JUL250000                250,000                15,000                    15,000
AUG200000                225,000                    25,000                    20,000
SEP275000                241,667                    22,500                    20,833
OCT350000                268,750                    30,000                    23,125
TABLE_B
RUNN_REVENUERUNN_COMMISSIONPROFIT/LOSS
                 268,750                    23,125                 245,625
oscar_ortiz
Partner - Specialist
Partner - Specialist

Neville,

I think you may be trying to do something like this:

If( RowNo() = 0,

Sum(REVENUE) / Count(REVENUE),

RangeAvg( ABOVE( RangeSum( REVENUE ),0,RowNo() ) )

)

Thanks

Oscar

nevilledhamsiri
Specialist
Specialist
Author

Dear Oscar,

Once I applied your expression, correct running average is calculated (as at SEP) but is picked & appeared in the total row only. This has to be shown before each BR_CODES!  Can you please what could be the reason & appreciate if the modified expression is forwarded!

I have attached two excel file as well for your ref.

Thanks

Neville

     

BR_CODEMONTH REVENUE ACQUISITION_COST INV_OTHER_INCOME FIXED_EXPENSES
RAJUL         6,892,201 1,113,069 2,100,831 3,730,930
RAAUG         7,190,963 910,909 2,514,500 4,181,955
RASEP         6,500,000 1,100,000 2,100,000 3,850,000
EHJUL         2,675,146 384,723 (168,547) 1,003,989
EHAUG         2,644,461 262,054 (137,098) 1,075,201
EHSEP         2,644,461 262,054 (137,098) 1,075,201
K7JUL             714,923 99,870 (18,503) 410,905
K7AUG             738,177 68,660 (25,595) 437,711
K7SEP             738,177 68,660 (25,595) 437,711
K9JUL         1,088,208 145,972 (26,411) 607,038
K9AUG         1,106,821 130,553 57,376 590,378
K9SEP         1,106,821 130,553 57,376 590,378
EMJUL         6,185,824 908,980 143,648 2,308,546
EMAUG         6,394,567 783,171 523,857 2,538,108
EMSEP         6,394,567 783,171 523,857 2,538,108
ASJUL         1,362,913 171,510 94,049 546,051
ASAUG         1,346,740 149,874 160,994 607,066
ASSEP         1,346,740 149,874 160,994 607,066
TAJUL             688,378 85,529 (16,300) 337,675
TAAUG             713,250 95,188 1,247 361,033
TASEP             713,250 95,188 1,247 361,033
MYJUL         1,386,786 196,622 32,293 637,114
MYAUG         1,393,789 211,653 29,653 685,471
MYSEP         1,393,789 211,653 29,653 685,471
KWJUL         1,978,907 337,108 (22,233) 769,713
KWAUG         2,271,812 267,363 73,240 859,696
KWSEP         1,978,907 337,108 (22,233) 769,713
LWJUL         1,211,797 212,784 122,140 737,843
LWAUG         1,388,349 172,332 164,891 768,098
LWSEP         1,211,797 212,784 122,140 737,843
PAJUL             863,655 126,358 (19,628) 512,060
PAAUG             811,104 83,412 (9,752) 517,445
PASEP             863,655 126,358 (19,628) 512,060
GDJUL             460,808 52,130 (18,006) 294,921
GDAUG             463,772 24,213 (17,082) 333,540
GDSEP             463,772 24,213 (17,082) 333,540
BLJUL         2,015,615 322,607 55,042 1,089,059
BLAUG         2,053,307 238,509 149,433 1,122,053
BLSEP         2,053,307 238,509 149,433 1,122,053
PBJUL         2,127,336 358,277 24,376 847,249
PBAUG         2,159,191 397,732 115,694 897,907
PBSEP         2,200,000 450,000 150,000

950,000

 

BR_CODECLAIMS
RA500000
EH200000
K7150000
K9200000
EM450000
AS150000
TA50000
MY75000
KW125000
LW250000
PA300000
GD225000
BL150000
PB250000