Aspose.Words Multiplication and division LINQ Reporting Engine Syntax

Hey,

How can I achieve multiplication in template for LINQ Reporting Engine? Let’s say I have 2 values read from datasource <<[ProductAAmount]>> and <<[ProductBAmount]>>. I can render/see them correctly on files that I generate from the template. What is the syntax to multiply these values together and to get that value to render? You can find example document attached to this post. testReport_v1.docx (37.5 KB)

Another question would be how can I format percentage decimals the way I want?

Thank you in advance!

@Suikero

LINQ Reporting Engine enables to use a subset of C# language in template expressions. See Using Operators for more information on supported operators.

So, to multiply two values, you can use the following template syntax: <<[ProductAAmount * ProductBAmount]>>.

Unfortunately, this requirement is not clear enough, please share more details on this matter.

In general, you can apply standard numeric format strings and custom numeric format strings directly in templates by using syntax like this: <<[ProductAAmount]:"F">>. See Outputting Expression Results for more information.

Hey,

thank you for the answers. They helped a lot!

One more question came to mind. I have managed to multiply the values using the syntax you provided. How can I Sum the multiplied totals together? Or what is syntax for it? I have attached updated example heretestReport_v1.docx (38.2 KB)

@Suikero

You can use LINQ extension methods directly in template expressions to output aggregate values for collections. The list of supported LINQ extension methods with examples can be found at Enumeration Extension Methods.

In your case, template syntax might be like this: <<[xml.products.productgroups.productgroup.Sum(g => g.ProductAAmount * g.ProductBAmount)]>>.

Hey,

couple more questions came in. Please find example document attached here.Test_document.docx (15.7 KB) and example xml which we are using to populate the word file here test.zip (270 Bytes)

I have a table and I can calculate values there fine. However, summing the calculated values together to the bottom of the table seems to be a challenge since we are using something on the table itself with the calculations. Do you have any pointers which syntax would solve the problem/can calculate everything together nicely?

@Suikero

We have troubles in building a report from the provided template and data. Maybe, you use an XSD (XML schema) file in addition? Could you please also provide source code you use for building a report? Thanks for your cooperation.

Hey,

I’m afraid that sharing the source code is not possible, but for me that isn’t the problem as it works and I can access all the values of the XML.

Just wondering about example syntax which could calculate the totals in the “Totals”-row in the example document. All the calculations before the “Totals”-row already work.

@Suikero As an option, you can use MS Word formula field {=SUM(ABOVE)} to calculate sum of values in the column.
Also, you can try using LINQ syntax like this:

<<[xml.products.productgroups.productgroup.Sum(g => (g.Name=="Desktop") ? 235 : (g.Name=="Laptop") ? 194 : (g.Name=="Monitor") ? 312 : (g.Name=="Phone") ? 50 : (g.Name=="Tablet") ? 121 : 0)]>>