Forum Discussion

tgjones43's avatar
tgjones43
Helper IV
7 years ago

Custom column based on several other columns

This is a tricky one to describe, so here goes. I have attached a much simplified example. The data relates to fish sampling data in rivers.

 

I have a table with thousands of 8-digit numbers in the first column ([ID] - only one number is given in the example). Each 8-digit number occupies 30-40 rows, with data in several other columns. In one of those other columns ([ID 2]), and for some rows only, is another 8-digit number that is linked to values in other columns and is repeated several times. The value in [ID 2] is assigned when a new survey is undertaken, but the names in columns 3 and 4 can be the same, if the survey type is the same as the previous survey type (e.g. rows 4 and 5).

 

What I need to do is have some way of creating a custom column that assigns a value of Survey 1, Survey 2, Survey 3 to match the values in [ID 2] i.e. all values of 21779013 = Survey 1.

 

That would be easy if there weren't thousands of values in [ID], with each value of [ID] having unique values in [ID 2] i.e. for the next value of [ID] (21770162), the values in [ID 2] would be totally different, and unique to that particular value in [ID].

 

Does anyone have any ideas? Thank you!

 

9 Replies

    • tgjones43's avatar
      tgjones43
      Helper IV

      Thank you for the response. I have pasted the data below, with the column at the end showing the expected outcome.

       

      IDID 2NameValueCustom Column
      21770161nullAltitude284null
      21770161nullWidth5null
      2177016121779013ProgramCore Fisheries Monitoring ProgramSurvey 1
      2177016121779155ProgramCore Fisheries Monitoring ProgramSurvey 2
      2177016121779296ProgramWater Framework Directive ProgrammeSurvey 3
      2177016121779013PurposeTemporalSurvey 1
      2177016121779155PurposeTemporalSurvey 2
      2177016121779296PurposeSalmonidSurvey 3
      2177016121779013Repeat frequency1 yearSurvey 1
      2177016121779155Repeat frequency1 yearSurvey 2
      2177016121779296Repeat frequency6 yearsSurvey 3
      2177016121779013Survey StrategyQuanitativeSurvey 1
      2177016121779155Survey StrategySemi-quantitativeSurvey 2
      2177016121779296Survey StrategySemi-quantitativeSurvey 3
      2177016121779013Guideline MethodPDC Electric FishingSurvey 1
      2177016121779155Guideline MethodPDC Electric FishingSurvey 2
      2177016121779296Guideline MethodElectric FishingSurvey 3
      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        So, could you just create a second query where you pull out all of the distinct values from ID2 and assign an Index to them. That way you should be able to easily relate that dimension table back to this fact table and have what you want, correct?