Forum Discussion

nExoR's avatar
nExoR
Copper Contributor
Jul 04, 2022

conditional columns

if there a way to project/extend columns conditionally? 

scenario: 

i want to make a resource query by name, and show some additional information based on resource type.

 

any hints?

4 Replies

  • wernerzirkel's avatar
    wernerzirkel
    Copper Contributor

    nExoR 

     

    I think you might create a new column with iif. Here's an example using the StormEvents table:

     

    StormEvents

    | where State =="CALIFORNIA"
    | distinct EventType, State
    | extend ItNeverRainsInCalifornia = iif(EventType =="Heavy Rain" and State =="CALIFORNIA", "it pours, man it pours", "") //if-then-else - else is left blank in this example

    • nExoR's avatar
      nExoR
      Copper Contributor
      thanks! i'm using similar logic now, i was hoping for some method to NOT have columns instead of having empty columns. this logic means, that for each object there will be multiple, unnecessary, empty columns for objects of a different type...

      anyway - thx for confirming.
      • wernerzirkel's avatar
        wernerzirkel
        Copper Contributor
        this would simple replace "Heavy Rain" in the existing column EventType by the String "it pours".

        StormEvents
        | where State =="CALIFORNIA"
        | distinct EventType, State
        | extend EventType = iif(EventType =="Heavy Rain" and State =="CALIFORNIA", "it pours",EventType)

Resources