Skip to main content

Hi All,

 

I have date values in five columns, however, not all rows have date values in all five columns. For example, row 1 has values for columns 1, 2 and 3; row 2 has values for columns 1, 2, 3 and 4; row 3 has values for columns 1, 2, 3, 4 and 5; row 4 has value for column 1 only; and row 5 has values for columns 1 and 2. The rest of the columns not mentioned in each row have <missing> values.

I want to create a new column called DATE and populate it with the last date before a column value of <missing>. For example, row 1 will have the date value from column 3; row 2 from column 4; row 3 from column 5; row 4 from column 1; and row 5 from column 2. Thanks for your help in advance.

RowDate1Date2

 

Date3

 

Date4Date5

 

DATE114/01/201815/10/201916/01/2020<missing><missing>

 

16/01/2020219/01/201513/01/201711/01/201801/01/2020<missing>

 

01/01/2020

 

318/01/201415/10/201511/01/201601/01/201910/01/202010/01/2020

 

417/01/2020<missing>

 

<missing>

 

<missing>

 

<missing>

 

17/01/2020

 

516/01/201901/01/2020<missing>

 

<missing>

 

<missing>

 

01/01/2020

 

Hi @geohabuk,

I think that setting a conditional attribute in the AttributeManager should achieve what you're looking for. There's a helpful article here on how to set If-Then Conditional Statements. You'll want to set some logic such as If Date5 has a value, set DATE to the value of Date5, ELSE IF Date4 has a value, set DATE to the value of Date4, and so on.

The filter goes from the broadest down to the last and most specific else. So in other words, FME will evaluate it in order of those IF statements set. I've put together a quick sample template file to show this based on a smaller sample dataset with 3 columns. Hope that helps!

 

 

sample-conditional-attribute.fmwt

Since there are only 5 date fields, this could be handled using AttributeCreator, with Conditional Values turned On (Click on the dropdown options for setting the value on the new Date field. This will then take 5 mutually exclusive conditions IF Date5 has a value then Date5 ElseIf Date4 has a value then Date4 etc.

If the date fields in question really are Missing then a quirk her is that it means the Attribute doesn't actually exist for these particular rows. A crazier way then that involves less clicking is AttributeRenamer. In the one Transformer, rename Date1 to "Date", then Date2 to "Date" , then Date3 to "Date" etc. This will end up for each Feature having the last non-missing Attribute renamed to Date. A similar method can be employed in AttributeCreator if want to leave the original Date fields in the output.

Otherwise there are more generic solutions using Lists and ListPopulator.


An alternative approach, give all the missing attributes a new value "Blank", create a list from all the date fields (if your date fields are numbered as per the example, this will create a list with the correct order), search the list for the first list value to match blank, use a listindexer to fetch the previous value or the last value if all values are populated.


There should be several ways. Assuming that every date is always 10 characters, you can concatenate all the 5 attribute values and then extract the last 10 characters to select the right-most date.

@Substring(@Value(Date1)@Value(Date2)@Value(Date3)@Value(Date4)@Value(Date5),-10)

Hi @geohabuk,

I think that setting a conditional attribute in the AttributeManager should achieve what you're looking for. There's a helpful article here on how to set If-Then Conditional Statements. You'll want to set some logic such as If Date5 has a value, set DATE to the value of Date5, ELSE IF Date4 has a value, set DATE to the value of Date4, and so on.

The filter goes from the broadest down to the last and most specific else. So in other words, FME will evaluate it in order of those IF statements set. I've put together a quick sample template file to show this based on a smaller sample dataset with 3 columns. Hope that helps!

 

 

sample-conditional-attribute.fmwt

Thank you all for your quick reply. I found @jovitaasafe's answer is the easiest with the sample template.


Reply