# Conditional apoc.map.setKey

Hi!

I was trying to conditionally set a key using `apoc.map.setKey` but am not getting it to work.
How would I go about doing something like

``````if value.selection is not null
apoc.map.setKey(n, 'who', {filter: value.selection, type: type})
``````

Any hints would be very much appreciated!

Nikolai

You can use WHERE for a general filter or perhaps CASE

`WITH CASE value.selection WHEN null THEN map ELSE apoc.map.setKey(map, 'who', {filter: value.selection, type: type}) END as map`

1 Like

Thanks a lot! This works well!