Forum Discussion

gianmarco's avatar
gianmarco
Helper IV
2 years ago
Solved

IF condition + WHERE

Dear All,

i have the following table:

FruitCityPreferred
BananaNY0
Kiwinullnull
AppleRome1
Orangenullnull
GrapePhilly0

 

I need to create a conditional column for which: IF City = null THEN City where Preferred = 1 ELSE City

Desired result as follows:

 

FruitCityPreferredNEW COLUMN
BananaNY0NY
KiwinullnullRome
AppleRome1Rome
OrangenullnullRome
GrapePhilly0Philly

 

 

Thank you a lot
gianmarco

  • gianmarco , If this is the data then this column formula should work:

    Column =
    var _v = CALCULATE(Max(q1[City]), FILTER(q1, q1[Preferred] = 1))
    return
    IF(q1[City] = "null", _v, q1[City])
     
    Thank You.

2 Replies

  • gianmarco , If this is the data then this column formula should work:

    Column =
    var _v = CALCULATE(Max(q1[City]), FILTER(q1, q1[Preferred] = 1))
    return
    IF(q1[City] = "null", _v, q1[City])
     
    Thank You.
  • Just a question to give you the best logic and solution. When Preferred = 1 the expected outcome should always be "Rome" or are you expecting other cities as well?