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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
tincholiver
Creator III
Creator III

prorate costs

Hello everyone! I don't know how to solve the following case, I hope you can help me.
I have the following table with data:

AREAPROJECTAMOUNT
SALESPROYECTO A4.363.428
SALESPROYECTO B8.277.968
SALESPROYECTO C272.139
SALESPROYECTO D686.263
SALESPROYECTO E54.328
SALESPROYECTO F606.148
INDIRECT COSTSADMINISTRACION-866.440
INDIRECT COSTSINFRAESTRUCTURA-4.300.843
INDIRECT COSTSOPERACIONES-4.115.433
EXPENSESTAXES-419.938

 

The idea is to be able to prorate indirect costs and expenses to each project according to its percentage of sales with respect to the total.

This would be the expected result.

the administration costs for project A is equal to the sales amount divided by the total sales amount multiplied by administration. Same criteria for other costs and expenses.

 

AREAPROJECTPROYECTO APROYECTO BPROYECTO CPROYECTO DPROYECTO EPROYECTO FTOTAL
SALESSALES4.363.4288.277.968272.139686.26354.328606.14814.260.274
INDIRECT COSTSADMINISTRACION-265.118-502.961-16.535-41.697-3.301-36.829-866.440
INDIRECT COSTSINFRAESTRUCTURA-1.315.993-2.496.603-82.076-206.974-16.385-182.812-4.300.843
INDIRECT COSTSOPERACIONES-1.259.260-2.388.974-78.538-198.052-15.679-174.931-4.115.433
EXPENSESTAXES-128.495-243.770-8.014-20.209-1.600-17.850-419.938
TOTAL 1.394.5632.645.66086.976219.33117.363193.7264.557.620

 

I hope I was clear. Thank you

 

5 Replies
Saravanan_Desingh

Try this,

tab1:
LOAD * INLINE [
    AREA, PROJECT, AMOUNT
    SALES, PROYECTO A, 4363428
    SALES, PROYECTO B, 8277968
    SALES, PROYECTO C, 272139
    SALES, PROYECTO D, 686263
    SALES, PROYECTO E, 54328
    SALES, PROYECTO F, 606148
    INDIRECT COSTS, ADMINISTRACION, -86644
    INDIRECT COSTS, INFRAESTRUCTURA, -4300843
    INDIRECT COSTS, OPERACIONES, -4115433
    EXPENSES, TAXES, -419938
];
Left Join(tab1)
LOAD Sum(AMOUNT) As TAMT
Resident tab1
Where AREA='SALES';

Left Join(tab1)
LOAD AMOUNT As ADMAMT
Resident tab1
Where PROJECT='ADMINISTRACION';

Left Join(tab1)
LOAD AMOUNT As INFAMT
Resident tab1
Where PROJECT='INFRAESTRUCTURA';

Left Join(tab1)
LOAD AMOUNT As OPAMT
Resident tab1
Where PROJECT='OPERACIONES';

Left Join(tab1)
LOAD AMOUNT As TXAMT
Resident tab1
Where PROJECT='TAXES';

tab2:
LOAD PROJECT, AMOUNT,
AMOUNT*ADMAMT/TAMT As ADMINISTRACION,
AMOUNT*INFAMT/TAMT As INFRAESTRUCTURA,
AMOUNT*OPAMT/TAMT As OPERACIONES,
AMOUNT*TXAMT/TAMT As TAXES
Resident tab1
Where AREA='SALES';


tab3:
Generic
LOAD 'SALES' AS Project, PROJECT, AMOUNT
Resident tab2;
Generic
LOAD 'ADMINISTRACION' AS Project, PROJECT, ADMINISTRACION
Resident tab2;
Generic
LOAD 'INFRAESTRUCTURA' AS Project, PROJECT, INFRAESTRUCTURA
Resident tab2;
Generic
LOAD 'OPERACIONES' AS Project, PROJECT, OPERACIONES
Resident tab2;
Generic
LOAD 'TAXES' AS Project, PROJECT, TAXES
Resident tab2;
Generic
LOAD 'TOTAL' AS Project, PROJECT, AMOUNT+ADMINISTRACION+INFRAESTRUCTURA+OPERACIONES+TAXES
Resident tab2;

Drop Table tab1, tab2;
Saravanan_Desingh

Output:

commQV01.PNG

Saravanan_Desingh

I am not sure, how you have calculated the Total. But I did as 

AMOUNT+ADMINISTRACION+INFRAESTRUCTURA+OPERACIONES+TAXES
tincholiver
Creator III
Creator III
Author

Thanks for your answer Sharan 7, it works very well, only 2 things: how would you solve it if there are different projects and different indirect costs and expenses? For example, in a month there may be two projects with only indirect costs and in another with only expenses. The second question is, how would you do to leave the table with the columns AREA, PROJECT, AMOUNT, PERCENT.

 

I am very thankfull for your help

Saravanan_Desingh

Yes, you are right. Most of the things are hard coded here.