If/EndIf in table in report

Hello,

I am producing a report with a table and I need to exclude certain fields based on criteria. These fields can be grouped. so e.g if field 1 has a certain value, then field 2, 3, 4 should not be shown. This works outside of a table as follows:

<<If: [Field 1]=”No”>>
<<[Field 2]>>:<<Field 3>>:<<[Field 4]>>
<< EndIf>>
<<If: [Field 5]=”No”>>
<<[Field 6]>>:<<[Field 7]>>:<<[Field 8]>>
<< EndIf>>

However once I try putting it into a table and spanning multiple cells in a row it doesn’t work. If I put the << EndIf>> in the same cell as the << End>> I get the error “Found 1 unmatched ‘Start’”. If I put the << EndIf> in a different cell, it doesn’t give an error, but it doesn’t display correctly.

I can get it to work by putting separate if/endif in each cell but makes the template hard to read and seems unnecessary, plus I have 20 groupings like this.

Are If/EndIf’s allowed span multiple cells in a row in a table?

Note I had to put spaces in all the endif and end’s above so they would be displayed correctly.
Thanks,
Steve

Hi Steve, are you able to take a printscreen directly from your template and from the generated PDF, thanks.

Sure. This is the template
image

This is the output
image

The EndIf has been implied by the end of the Date cell, and the endif in the JobNo cell is ignored.

Note the first line is correct, as [Answer 1] is equal to Nie in first entry, but not in the second entry.

So… you would like to show/hide all columns separately depending on the If: EndIf?

Hi Aleksi,

I would like to show/hide a grouping of cells depending on the if:Endif. So outside of a table it would look like below where there is only 1 if/endif for the 4 fields. When I put the code below in a table it doesn’t like it.

<<Start:OrderBy( Select(Answers[Id], OR([Level 2 count]>0,[Level 2 count]>0), TRUE),[Level 2 count],TRUE)>>
<<If: [Answer 1]=”Nie”>>
<<[Created]>>:<<[Auditor].[Name]>>:<<[Operator]>>:<<[Job No]>>
<>
<>

Maybe if I explain what I am ultimately trying to do it will be clearer and maybe there is a simpler way.

I am working towards doing what is shown below (I had hidden some of the lines above for simplicity) where I show new lines for entries that are in the same row in the google sheet. The top line below is the google sheet data, and the bottom part is how I would like the report for that line to look.

The form has 3 (really it has more) questions e.g. Question 1, Answer 1, Comment 1, Question 3, Answer 3, Comment 3, and depending on the answer they are included or excluded in the report (Note the whole row is not excluded, just the 3 fields and the common fields e.g. Date, job No etc). The report however should show each question that has the answer Nie (No) on a new line and not show questions that don’t have the answer Nie.

Maybe there is a simpler way of doing what I am trying to do?

Thanks,
Steve

It sounds your column structure is not correct for your needs if they need to be in the same table (on the pdf)… I will test this. Though you can do that if your group Question, Answer and Comment is a child table. Then you can trigger the pdf from the child table and for other fields like Date, Job No you can write with the Deref expression.

As I thought, with your construct it’s not possible to have the data in the same table. Though you can have it almost. When you write the Start: expression before the table and End after the table, you can have this kind of result…

As you can see that the vertical border between 2nd and 3rd column is not exactly in the same position. Also it will produce two lines between tables. You should also keep in mind that if you use If: & EndIf it will hide values but it keeps the blank row in your table.

1 Like

Thank you very much for trying this out Aleksi.

With regards the child table, I understand it could work that way, but it does not suit my app. The form looks better when all the entries are directly in the form. Easy for the user to understand.

I will try your suggestion. Since what I want works outside of a table, I thought it would work inside a table, as the table was just formatting, but it seems that is not the case.

One thing I have noticed though, is that you can only use each field once. So it will allow me put <<[Question 1]>> on one line, and <<[Question 2]>> on another line, with the << end>> after. However it will not allow me put the same <<[Question 1]>> twice, even in adjacent columns on same row. If it supported this, then I could get what I wanted, by just putting an if/endif around every cell entry.

I’d be interested to know, if you have time, if you see the same issue with trying to use the same field twice?

Thanks,
Steve

This solution worked and I was also able to put the if/endif outside of each table to get exactly what I wanted.

Thanks for your help.
Steve

You’re welcome