Lookup across multiple columns

Evening,

This one is a little over my headโ€ฆ

I need to lookup a value in one column and if it exists in any one of 5 other columns, it needs to return the column to the right of where it is found.

I could use LOOKUP for one instance but donโ€™t know how to do it for multiple columns?

LOOKUP( survey_branch_number , survey , branch_A_number , branch_A_assets )

I need to lookup:
[survey_branch_number]

In these columns:
[branch_A_number], [branch_B_number], [branch_C_number], [branch_D_number], [branch_E_number]

And return the corresponding:
[branch_A_assets], [branch_B_assets], [branch_C_assets], [branch_D_assets], [branch_E_assets]

And, as if this wasnโ€™t tricky enough, the expression will also need to account for the following:

SELECT(
survey[branch_x_assets],
AND(
[select_asset_type] = [_THISROW].[select_asset_type],
[select_cabinet_to_survey] = [_THISROW].[select_cabinet_to_survey],
[lcs] = [_THISROW].[LCS]
))

Sample of survey table below:

Thanks in advanceโ€ฆ

0 16 1,059
16 REPLIES 16

IFS(
	ISNOTBLANK(LOOKUP(survey_branch_number , survey , branch_A_number , branch_A_assets)),
	LOOKUP(survey_branch_number , survey , branch_A_number , branch_A_assets),
	TRUE,
	IFS(
		ISNOTBLANK(LOOKUP(survey_branch_number , survey , branch_B_number , branch_B_assets)),
		LOOKUP(survey_branch_number , survey , branch_B_number , branch_B_assets),
		TRUE,
		IFS(
			ISNOTBLANK(LOOKUP(survey_branch_number , survey , branch_C_number , branch_C_assets)),
			LOOKUP(survey_branch_number , survey , branch_C_number , branch_C_assets),
			TRUE,
			IFS(
				ISNOTBLANK(LOOKUP(survey_branch_number , survey , branch_D_number , branch_D_assets)),
				LOOKUP(survey_branch_number , survey , branch_D_number , branch_D_assets),
				TRUE,LOOKUP(survey_branch_number , survey , branch_E_number , branch_E_assets)
			)
		)
	)
)

Hi @LeventK,

Thank you very much for thatโ€ฆ! You make that look easyโ€ฆ!

Iโ€™ll give that a go right away and will report backโ€ฆ

Cheersโ€ฆ

This:

reformatted for my clarity
IFS(
  ISNOTBLANK(
    LOOKUP(
      survey_branch_number,
      survey,
      branch_A_number,
      branch_A_assets
    )
  ),
    LOOKUP(
    survey_branch_number,
    survey,
    branch_A_number,
    branch_A_assets
    ),
	TRUE,
    IFS(
      ISNOTBLANK(
        LOOKUP(
          survey_branch_number,
          survey,
          branch_B_number,
          branch_B_assets
        )
      ),
        LOOKUP(
          survey_branch_number,
          survey,
          branch_B_number,
          branch_B_assets
        ),
      TRUE,
        IFS(
          ISNOTBLANK(
            LOOKUP(
              survey_branch_number,
              survey,
              branch_C_number,
              branch_C_assets
            )
          ),
            LOOKUP(
              survey_branch_number,
              survey,
              branch_C_number,
              branch_C_assets
            ),
          TRUE,
            IFS(
              ISNOTBLANK(
                LOOKUP(
                  survey_branch_number,
                  survey,
                  branch_D_number,
                  branch_D_assets
                )
              ),
                LOOKUP(
                  survey_branch_number,
                  survey,
                  branch_D_number,
                  branch_D_assets
                ),
              TRUE,
                LOOKUP(
                  survey_branch_number,
                  survey,
                  branch_E_number,
                  branch_E_assets
                )
            )
        )
    )
)

simplifies to:

easier to read
IFS(
	ISNOTBLANK(
    LOOKUP(
      survey_branch_number,
      survey,
      branch_A_number,
      branch_A_assets
    )
  ),
    LOOKUP(
      survey_branch_number,
      survey,
      branch_A_number,
      branch_A_assets
    ),
  ISNOTBLANK(
    LOOKUP(
      survey_branch_number,
      survey,
      branch_B_number,
      branch_B_assets
    )
  ),
    LOOKUP(
      survey_branch_number,
      survey,
      branch_B_number,
      branch_B_assets
    ),
  ISNOTBLANK(
    LOOKUP(
      survey_branch_number,
      survey,
      branch_C_number,
      branch_C_assets
    )
  ),
    LOOKUP(
      survey_branch_number,
      survey,
      branch_C_number,
      branch_C_assets
    ),
  ISNOTBLANK(
    LOOKUP(
      survey_branch_number,
      survey,
      branch_D_number,
      branch_D_assets
    )
  ),
    LOOKUP(
      survey_branch_number,
      survey,
      branch_D_number,
      branch_D_assets
    ),
  TRUE,
    LOOKUP(
      survey_branch_number,
      survey,
      branch_E_number,
      branch_E_assets
    )
)

simplifies to:

more efficient
ANY(
  LIST(
    LOOKUP(
      survey_branch_number,
      survey,
      branch_A_number,
      branch_A_assets
    ),
    LOOKUP(
      survey_branch_number,
      survey,
      branch_B_number,
      branch_B_assets
    ),
    LOOKUP(
      survey_branch_number,
      survey,
      branch_C_number,
      branch_C_assets
    ),
    LOOKUP(
      survey_branch_number,
      survey,
      branch_D_number,
      branch_D_assets
    ),
    LOOKUP(
      survey_branch_number,
      survey,
      branch_E_number,
      branch_E_assets
    )
  )
  - LIST("")
)

Hi @Steve,

Thanks for coming inโ€ฆ and for your time spent on thisโ€ฆ!

Iโ€™m busy trying to figure out where to insert your expression in my Initial Valueโ€ฆ

Please could you advise?

ANY(
LIST(
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_A_numberโ€,
โ€œbranch_A_assetsโ€
),
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_B_numberโ€,
โ€œbranch_B_assetsโ€
),
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_C_numberโ€,
โ€œbranch_C_assetsโ€
),
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_D_numberโ€,
โ€œbranch_D_assetsโ€
),
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_E_numberโ€,
โ€œbranch_E_assetsโ€
)
)
-LIST("")
)

This is a nonsense statement. The Initial value expression is an expression. I provided you with an expression. Put my expression in Initial valueโ€ฆif thatโ€™s actually where you want itโ€ฆ

You havenโ€™t explained (clearly) what you want to do with this list youโ€™ve asked us to generate for you. If you want the user to select one of the values from a dropdown menu, use what weโ€™ve provided as a columnโ€™s Valid If expression. If you want the user to choose more than one value, make the column type EnumList.

Sorry, my misunderstanding @Steveโ€ฆ I already have something in InitialValue and I didnโ€™t realise this was to replace thatโ€ฆ

IFS(

ISBLANK([survey_branch_number]),

ORDERBY(
SELECT(asset[id],
IN([id],
SORT(
UNIQUE(
SELECT(rf_design[Source Asset ID],
AND(
[_THISROW].[select_asset_type]=[source_asset_type],
[main_asset_name] = [_THISROW].[select_cabinet_to_survey],
[lcs] = [_THISROW].[LCS]
))
+
SELECT(rf_design[Destination Asset ID],
AND(
[_THISROW-2].[select_asset_type]=[destination_asset_type],
[main_asset_name] = [_THISROW-2].[select_cabinet_to_survey],
[lcs] = [_THISROW-2].[LCS],
NOT(
[destination_asset_type]=โ€˜Cabinetโ€™
)))
),FALSE
)),TRUE
),[asset_name]
),

AND(
[survey_type] = โ€œSingle Assetโ€,
COUNT(
SELECT(
survey[_ROWNUMBER],
AND(
[survey_branch_number] = [_THISROW].[survey_branch_number],
[surveyor_email] = USEREMAIL(),
(COUNT([survey_asset_id]) = 1)
)))>0
),

LOOKUP(
MAX(
SELECT(
survey[_ROWNUMBER],
AND(
[survey_branch_number] = [_THISROW].[survey_branch_number],
[surveyor_email] = USEREMAIL(),
(COUNT([survey_asset_id]) = 1)
))),
โ€œsurveyโ€,"_ROWNUMBER",โ€œsurvey_asset_idโ€
),

AND(
[survey_type] = โ€œMultiple Assetsโ€,
COUNT(
SELECT(
survey[_ROWNUMBER],
AND(
[survey_branch_number] = [_THISROW].[survey_branch_number],
[surveyor_email] = USEREMAIL(),
(COUNT([survey_asset_id]) > 1),
OR(
[select_asset_type] = โ€œCAT6Aโ€,
[select_asset_type] = โ€œFibreโ€,
[select_asset_type] = โ€œJumperโ€,
[select_asset_type] = โ€œPowerโ€
))))>0
),

LOOKUP(
MAX(
SELECT(
survey[_ROWNUMBER],
AND(
[survey_branch_number] = [_THISROW].[survey_branch_number],
[surveyor_email] = USEREMAIL(),
(COUNT([survey_asset_id]) > 1),
OR(
[select_asset_type] = โ€œCAT6Aโ€,
[select_asset_type] = โ€œFibreโ€,
[select_asset_type] = โ€œJumperโ€,
[select_asset_type] = โ€œPowerโ€
)))),
โ€œsurveyโ€,"_ROWNUMBER",โ€œsurvey_asset_idโ€
)
)

-[branch_A_assets]
-[branch_B_assets]
-[branch_C_assets]
-[branch_D_assets]
-[branch_E_assets]

@Steve & @LeventK

Thank you both for your timeโ€ฆ Itโ€™s 02:30 in the UK and I canโ€™t think straight any moreโ€ฆ Iโ€™ll get some sleep and pick this up when I surfaceโ€ฆ Cheersโ€ฆ

Hi @Steve and @LeventK,

I have your expression in a [test_column] ValidIf and Iโ€™m getting an error:

Column Type โ€˜Enumโ€™ has an invalid data validation constraint

I tried this ValidIf expression:

ANY(
LIST(
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_A_numberโ€,
โ€œbranch_A_assetsโ€
),
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_B_numberโ€,
โ€œbranch_B_assetsโ€
),
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_C_numberโ€,
โ€œbranch_C_assetsโ€
),
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_D_numberโ€,
โ€œbranch_D_assetsโ€
),
LOOKUP(
โ€œsurvey_branch_numberโ€,
โ€œsurveyโ€,
โ€œbranch_E_numberโ€,
โ€œbranch_E_assetsโ€
)
)

  • LIST("")
    )

I also tried this ValidIf but it yeilds the same error:

IFS(
ISNOTBLANK(LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_A_numberโ€, โ€œbranch_A_assetsโ€)),
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_A_numberโ€, โ€œbranch_A_assetsโ€),
TRUE,
IFS(
ISNOTBLANK(LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_B_numberโ€, โ€œbranch_B_assetsโ€)),
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_B_numberโ€, โ€œbranch_B_assetsโ€),
TRUE,
IFS(
ISNOTBLANK(LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_C_numberโ€, โ€œbranch_C_assetsโ€)),
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_C_numberโ€, โ€œbranch_C_assetsโ€),
TRUE,
IFS(
ISNOTBLANK(LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_D_numberโ€, โ€œbranch_D_assetsโ€)),
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_D_numberโ€, โ€œbranch_D_assetsโ€),
TRUE,
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_E_numberโ€, โ€œbranch_E_assetsโ€)
)
)
)
)

Iโ€™ve taken a look here:

and noted this:

Make sure your Enum and/or EnumList columns have all possible values explicitly defined, OR make sure Allow other values is ON .

Iโ€™ve gone through all of the columns involved in the lookup and confirmed that that all have โ€œallow other valuesโ€ set to ON.

I also tried wrapping the lookuo in a SPLIT() but got a NUL result:

I created a list to help troubleshoot:

UNIQUE(
SELECT(
survey[branch_A_assets],
[branch_A_number] > 0
)
)

And I get a โ€œThis entry is invalidโ€ error where an item is a coma separated value:

But I donโ€™t get the โ€œThis entry is invalidโ€ error where an item is a not coma separated value:

Could this be related to main issue?

Column Type โ€˜Enumโ€™ has an invalid data validation constraint

Any advice would be appreciatedโ€ฆ

Remove data validation for the spreadsheet column.

Hi @Steve

Any chance it has something to do with this odd behaviour?

I created a list to help troubleshoot:

UNIQUE(
SELECT(
survey[branch_A_assets],
[branch_A_number] > 0
)
)

And I get a โ€œThis entry is invalidโ€ error where an item is a coma separated value:

But I donโ€™t get the โ€œThis entry is invalidโ€ error where an item is a not coma separated value:

Try this:

SORT(
  UNIQUE(
    SPLIT(
      (
        LIST(
          LOOKUP(
            survey_branch_number,
            survey,
            branch_A_number,
            branch_A_assets
          ),
          LOOKUP(
            survey_branch_number,
            survey,
            branch_B_number,
            branch_B_assets
          ),
          LOOKUP(
            survey_branch_number,
            survey,
            branch_C_number,
            branch_C_assets
          ),
          LOOKUP(
            survey_branch_number,
            survey,
            branch_D_number,
            branch_D_assets
          ),
          LOOKUP(
            survey_branch_number,
            survey,
            branch_E_number,
            branch_E_assets
          )
        )
        - LIST("")
      ),
      " , "
    )
  )
)

Hi @Steve,

Thank youโ€ฆ I did as suggested above and not getting the error any moreโ€ฆ and moving forward againโ€ฆ

Cheersโ€ฆ

Hi @LeventK,

Thanks for your time.

Iโ€™d be very grateful if you could spare a little more to help me apply your expression?

It feels like it belongs in this ValidIf in [asset_name] EnumList. BAseType Ref, (asset table)

Iโ€™ve tried it in a coupe of places but canโ€™t get it to work.

Iโ€™ve also tried it on itโ€™s own as an Initial Value

If you do have time, hereโ€™s how the current ValidIf flows:

  • Produce a full list of asset names for this cabinet from rf_design table if survey branch number is blank i.e. if itโ€™s the first survey on this cabinet

IFS(

ISBLANK([survey_branch_number]),

ORDERBY(
SELECT(asset[id],
IN([id],
SORT(
UNIQUE(
SELECT(rf_design[Source Asset ID],
AND(
[_THISROW].[select_asset_type]=[source_asset_type],
[main_asset_name] = [_THISROW].[select_cabinet_to_survey],
[lcs] = [_THISROW].[LCS]
))
+
SELECT(rf_design[Destination Asset ID],
AND(
[_THISROW-2].[select_asset_type]=[destination_asset_type],
[main_asset_name] = [_THISROW-2].[select_cabinet_to_survey],
[lcs] = [_THISROW-2].[LCS],
NOT(
[destination_asset_type]=โ€˜Cabinetโ€™
)))
),FALSE
)),TRUE
),[asset_name]
),

  • if itโ€™s a survey of single asset by this surveyor

AND(
[survey_type] = โ€œSingle Assetโ€,
COUNT(
SELECT(
survey[_ROWNUMBER],
AND(
[survey_branch_number] = [_THISROW].[survey_branch_number],
[surveyor_email] = USEREMAIL(),
(COUNT([survey_asset_id]) = 1)
)))>0
),

  • then return the MAX survey_asset_id (one)

LOOKUP(
MAX(
SELECT(
survey[_ROWNUMBER],
AND(
[survey_branch_number] = [_THISROW].[survey_branch_number],
[surveyor_email] = USEREMAIL(),
(COUNT([survey_asset_id]) = 1)
))),
โ€œsurveyโ€,"_ROWNUMBER",โ€œsurvey_asset_idโ€
),

  • if itโ€™s a survey of multiple assets - of certain cable types - by this surveyor

AND(
[survey_type] = โ€œMultiple Assetsโ€,
COUNT(
SELECT(
survey[_ROWNUMBER],
AND(
[survey_branch_number] = [_THISROW].[survey_branch_number],
[surveyor_email] = USEREMAIL(),
(COUNT([survey_asset_id]) > 1),
OR(
[select_asset_type] = โ€œCAT6Aโ€,
[select_asset_type] = โ€œFibreโ€,
[select_asset_type] = โ€œJumperโ€,
[select_asset_type] = โ€œPowerโ€
))))>0
),

  • then return MAX survey_asset_id (many)

LOOKUP(
MAX(
SELECT(
survey[_ROWNUMBER],
AND(
[survey_branch_number] = [_THISROW].[survey_branch_number],
[surveyor_email] = USEREMAIL(),
(COUNT([survey_asset_id]) > 1),
OR(
[select_asset_type] = โ€œCAT6Aโ€,
[select_asset_type] = โ€œFibreโ€,
[select_asset_type] = โ€œJumperโ€,
[select_asset_type] = โ€œPowerโ€
)))),
โ€œsurveyโ€,"_ROWNUMBER",โ€œsurvey_asset_idโ€
)
)

  • this produces 6 asset names to chose from before a branch number is selected

  • if branch 1 is selected then the three assets from this surveyorโ€™s last survey are presented

  • if branch 2/3/4/5 are selected, then your expression needs to kick into action:
  • please could you advise where to insert it?

IFS(
ISNOTBLANK(LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_A_numberโ€, โ€œbranch_A_assetsโ€)),
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_A_numberโ€, โ€œbranch_A_assetsโ€),
TRUE,
IFS(
ISNOTBLANK(LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_B_numberโ€, โ€œbranch_B_assetsโ€)),
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_B_numberโ€, โ€œbranch_B_assetsโ€),
TRUE,
IFS(
ISNOTBLANK(LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_C_numberโ€, โ€œbranch_C_assetsโ€)),
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_C_numberโ€, โ€œbranch_C_assetsโ€),
TRUE,
IFS(
ISNOTBLANK(LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_D_numberโ€, โ€œbranch_D_assetsโ€)),
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_D_numberโ€, โ€œbranch_D_assetsโ€),
TRUE,
LOOKUP(โ€œsurvey_branch_numberโ€, โ€œsurveyโ€,
โ€œbranch_E_numberโ€, โ€œbranch_E_assetsโ€)
)
)
)
)

  • Many thanksโ€ฆ

Steve
Platinum 4
Platinum 4

Try:

UNIQUE(
  SORT(
    SPLIT(
      (
        SELECT(
          survey[branch_A_assets],
          AND(
            ([_THISROW].[survey_branch_number] = [branch_A_number]),
            ([_THISROW].[select_asset_type] = [select_asset_type]),
            ([_THISROW].[select_cabinet_to_survey] = [select_cabinet_to_survey]),
            ([_THISROW].[LCS] = [lcs])
          )
        )
        + SELECT(
          survey[branch_B_assets],
          AND(
            ([_THISROW].[survey_branch_number] = [branch_B_number]),
            ([_THISROW].[select_asset_type] = [select_asset_type]),
            ([_THISROW].[select_cabinet_to_survey] = [select_cabinet_to_survey]),
            ([_THISROW].[LCS] = [lcs])
          )
        )
        ...
        + SELECT(
          survey[branch_E_assets],
          AND(
            ([_THISROW].[survey_branch_number] = [branch_E_number]),
            ([_THISROW].[select_asset_type] = [select_asset_type]),
            ([_THISROW].[select_cabinet_to_survey] = [select_cabinet_to_survey]),
            ([_THISROW].[LCS] = [lcs])
          )
        )
      ),
      " , "
    )
  )
)

Hi @Steve,

I guess once I get the other bit working Iโ€™ll apply thisโ€ฆ I can see what itโ€™s going to doโ€ฆ Cheersโ€ฆ

Hi @Steve,

I donโ€™t use any data validation on the excel sheet but I went in anyway and cleared all just in caseโ€ฆ Still getting the same errorโ€ฆ

I did notice that the number columns in the spreadsheet were formatted to โ€œtextโ€ so Iโ€™ve changed them to numbers and am busy testing nowโ€ฆ

Corrected formatting in sheet and testedโ€ฆ Still getting the same errorโ€ฆ

Top Labels in this Space