Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with SUMPRODUCT #1468

Open
vzczc opened this issue May 28, 2024 · 7 comments
Open

Problem with SUMPRODUCT #1468

vzczc opened this issue May 28, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@vzczc
Copy link

vzczc commented May 28, 2024

EPPlus usage

Commercial use (I have a commercial license)

Environment

Windows

Epplus version

7.1.3

Spreadsheet application

Excel (Latest 365 version)

Description

When filling the formula property with a formula that uses SUMPRODUCT where one of the factors is an IF that refers to the current row, the if is preceeded by @ in the formula in Excel.

var doubleQuote = """";
sht.Cells[row, col].FormulaR1C1 = "IFERROR(SUMPRODUCT(IF(rngCurrency=RC1,1,0),rngLedgerDebit,rngDebitRate)/RC6),{doubleQuote})";

When opening this in Excel it looks like this. The problem is the @ before rngCurrency. If removed the formula calculates correctly
=IFERROR(SUMPRODUCT(IF(@rngCurrency=$A6;1;0);rngLedgerDebit;rngDebitRate)/$F6;"")

@vzczc vzczc added the bug Something isn't working label May 28, 2024
@vzczc
Copy link
Author

vzczc commented May 28, 2024

I made a workaround to avoid the IF statement that handles this case that does not have this problem.
var doubleQuote = """";
sht.Cells[row, col].FormulaR1C1 = "IFERROR(SUMPRODUCT(--(rngCurrency=RC1),rngLedgerDebit,rngDebitRate)/RC6),{doubleQuote})";

@OssianEPPlus
Copy link
Contributor

Thanks for your report! We're looking into this

@OssianEPPlus
Copy link
Contributor

OssianEPPlus commented May 29, 2024

I was able to re-create your error and we are working on a fix. Do note however:

var doubleQuote = """";
sht.Cells[row, col].FormulaR1C1 = "IFERROR(SUMPRODUCT(IF(rngCurrency=RC1,1,0),rngLedgerDebit,rngDebitRate)/RC6),{doubleQuote})";

Appears to have an inaccurate formula. The number of parenthesis do not match. There's three ( and four ) The doublequotes also are not escaped properly at least not if using c#. I assume what you were going for given that the
=IFERROR(SUMPRODUCT(IF(@rngCurrency=$A6;1;0);rngLedgerDebit;rngDebitRate)/$F6;"") formula works correctly if the @ is removed
was something more like:

var doubleQuote = "\"\"";
sheet.Cells[row,col].FormulaR1C1 = $"IFERROR(SUMPRODUCT(IF(rngCurrency=RC1,1,0),rngLedgerDebit,rngDebitRate)/RC6,{doubleQuote})";

It would potentially help and speed up your case if you could provide a workbook wherein this happens. Also note that as a commercial customer can always log in to our website and use our support portal to upload files and support tickets privately.

@vzczc
Copy link
Author

vzczc commented May 29, 2024

The doubleQuote issue was a result of copy/paste loosing this value, it is correct in the code. The same applies to the missing paren.

I will try to create an example for you, but am pressed for time today. I can upload an example in the support portal. There is also another problem when formulas like these are added, if I Calculate the workbook before saving, it takes a very long time. 15 seconds vs 1 if no calculation is done. It is probably easier for you to look at this when you have a test project that does this.

@OssianEPPlus
Copy link
Contributor

Any update on this? We have not received a ticket yet.

@vzczc
Copy link
Author

vzczc commented Jun 18, 2024 via email

@OssianEPPlus
Copy link
Contributor

No worries, just checking in as we cannot fully resolve the issue on our end without it.

@OssianEPPlus OssianEPPlus self-assigned this Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants