What I understood - going back to your first screenshot - is that you only want to display the columns Patient 1, Patient 2, Patient 3, Patient 4 and Patient 5.
As for Patient 6 and following columns, they are empty, so you want them to be hidden.
That was the assumption I made in my answer, and I believe taht’s exactly was it does 
So you’re right: I clearly missed something here - either in how I interpreted your need or in how I explained my solution.
Let’s have a look at two examples:
-
Column Patient 3 is empty
-
Columns Patient 1 and Patient 2 are empty
What the Data part does is creating new columns while skipping the empty ones.
-
In example 1. since Patient 3 is empty, the Patient new 3 values actually come from Patient 4
-
In example 2., Patient new 1 values and Patient new 2 values come from Patient 3 and Patient 4, respectively
In the worst case scenario, you’ll end up with as many new columns as your actual number of columns - that’swhen none of the original columns are empty.
In any other case, one or more of the new columns at the end will be empty.
The main drawback here is that we lose the original column names. We don’t know where the values came from.
For example, in case 2., how can we know that Simon was orignially in column Patient 3?
That’s where the Patient new # header columns come into play.
Now in the Layout, we need a way to display only the filled Patient new # columns.
Here’s what we know for sure: thanks to our work in Data, if there are 3 filled columns (regardless of their original position), their values will appear in Patient 1 new, Patient 2 new and Patient 3 new.
If there’s only 1 filled column, only the Patient 1 new will contain data.
We’ve also calculated the number of filled columns (see Number of new columns
).
So now, we just need to create X Data Grid components to handle all possible cases.
I started with the version that includes all columns, because I think it’s easier to set up once and then duplicate it, remove one column and adjust the visibility condition accordingly.
As shown in examples 1. and 2., we display a different Data Grid component depending on the number of filled columns.
- In 1., it’s the component with 3 Patient new # values columns and a visibility condition where
Number of new columns
equals 3
- In 2., it’s the component with 2 Patient new # values columns and a visibility condition where
Number of new columns
equals 2
Since the components are mutually exclusive and depend on the number of initially filled columns, the end user only see the Data Grid with the correct number of visible columns - i.e., the non-empty ones.
Again, please let us know if I missed anything - it would help us move closer to a solution 