I want to retrieve compressed data to Excel 2013 trough PI DataLink 2017 SP1.
To avoid bad values and duplicate values i made expression.
If badval('Tag') then 0 else if tagval('Tag') = prevval('Tag') then 0 else tagval('Tag')
This expression works well in some rows and gives desired results, but in some rows without rules shows following error:

Formula in Excel top line...
=PICompFilDat('From PI #2'!$C$27,'From PI #2'!$B$11,'From PI #2'!$B$12,"if tagval('Tag') = prevval('Tag') then 0 else If badval('Tag') then 0 else tagval('Tag')",0,11,"","inside")
Where is the problem and how to solve it?
Regards,
Igor