Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Defect acknowledgement with Nprinting Engine May 2022 SR2, please READ HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Totals with NPrinting Pixel Perfect

Hi

i' m creating a level with total from .qvw imported. I need to calculate some totals with a formulas, percentage for example.

It can possible calculate: total1 -  total2 / 100 ?

I can't modify data source in QlikView.

Thank for helping

14 Replies
Ruggero_Piccoli
Support
Support

Hi,

About totals and subtotals in PixelPerfect reports you can check https://www.youtube.com/watch?v=kR9K04RFX8o

To implement the formula you mentioned you can use scripting as show in Using scripts in a PixelPerfect report - Qlik NPrinting - YouTube

If you are not a developer, you should ask the help of one.

The C# script that you see in the video is the following:


private double topNTotalSales = 0; //topNRow rows total of sales

private double topNTotalMargin = 0; //topNRow rows total of sales

private int topRowCountTotalSales = 0; //show only first topNRow rows

//Reset the variables

private void OnSummaryResetTotalSales(object sender, System.EventArgs e) {

      topNTotalSales = 0;

      topRowCountTotalSales = 0;

      topNTotalMargin = 0;

}

//This function is executed one time for each of the first topNRows. Each time the function is executed, it adds the value of the row to the variables used to calculate the totals of sales and margins.

private void OnSummaryRowChangedTotalSales(object sender, System.EventArgs e) {

      if(topRowCountTotalSales < topNRow){

            //Retrieves the value of the sales field for each row

            //NPPsJt is the Qlik Sense column name

            topNTotalSales += (double)DetailReport.GetCurrentColumnValue("NPPsJt");

            //Retrieves the value of the sales field for each row and multiplies it by the margin in percentage to calculate the absolute margin

            topNTotalMargin += (double)DetailReport.GetCurrentColumnValue("NPPsJt") * (double)DetailReport.GetCurrentColumnValue("DBUzjm");

            //Add 1 to the row number counter

            topRowCountTotalSales += 1;

            }

}

//Returns the total of sales

private void OnSummaryGetResultTotalSales(object sender, SummaryGetResultEventArgs e) {

    e.Result = topNTotalSales;

    e.Handled = true;

}

//Calculates and returns the margin in percentage

private void OnSummaryGetResultTotalMargin(object sender, SummaryGetResultEventArgs e) {

    e.Result = topNTotalSales != 0 ? topNTotalMargin / topNTotalSales : 0;

    e.Handled = true;

}

Of course, you need to customize it to met your case, the source fields, for example, are different.

Best Regards,

Ruggero

---------------------------------------------

When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads as HELPFUL if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads as HELPFUL if you feel additional info is useful to others.



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.
gerald_lebret
Partner - Creator
Partner - Creator

Hello Ruggero,

I already posted a question in the forum but I was hoping to get a faster answer. I followed the nprinting tutorial which contains that piece of code.

However I am working on the part right before that, when you want to limit to the top N Row. I have copied and checked the code but no matter what I do, it doesn't work. I've got the entire table instead of just the top N Row. Could you please help??

 

Thank you very much.

 

Best Regards,

 

Gerald.

Ruggero_Piccoli
Support
Support

Hi,

I did some tests and the script is working. 

Starting from February 2020 there is a flag to enable and disable the execution of scripts in PixelPerfect reports:

Disable PixelPerfect scripts
Go to Settings->Report to disable all scripts in PixelPerfect reports. This removes access to protected resources on Qlik NPrinting Engine computers from PixelPerfect scripts.

So as first I suggest you to check that this flag is enabled.

Than please check that you associated the script with the event in the template:

band script before print.png

I hope this helps.

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.
gerald_lebret
Partner - Creator
Partner - Creator

Hello Ruggero,

 

Thank you SO MUCH for your help. It has been driving me crazy for days!!!!!! It was indeed deactivated in Nprinting!!!!

Thanks again, You ROCK!!!!!

Ruggero_Piccoli
Support
Support

Hi,

I'm happy to hear that you solved.

Best Regards,

Ruggero



Best Regards,
Ruggero
---------------------------------------------
When applicable please mark the appropriate replies as CORRECT. This will help community members and Qlik Employees know which discussions have already been addressed and have a possible known solution. Please mark threads with a LIKE if the provided solution is helpful to the problem, but does not necessarily solve the indicated problem. You can mark multiple threads with LIKEs if you feel additional info is useful to others.