Reputation: 81
It's a silly power BI question, but I can't figure it out using measures. This is a condition that I'd like to convert into a measure.
Condition:
i.) When there is no flight time for direction 'APAC' AND the first character in the code is 'V', will return '0', otherwise '1'.But other than code start with 'V', with or without date, will return blank.
ii.) When there is no flight time for direction 'AMER', will return '0'
iii.) Direction 'EMEA' , with or without time flight, will return blank
Expected result:
Attached with pbix: https://drive.google.com/file/d/1PEkk4PX37H4w8_1c6Dcl_TpEUa8IpEmW/view?usp=sharing
Appreciate any helps provided !
Upvotes: 0
Views: 657
Reputation: 12375
Try this one as a calculated column:
Result =
SWITCH(
TRUE(),
FlightTable[Direction] = "APAC",
IF(
LEFT(FlightTable[Code], 1) = "V",
IF (FlightTable[Flight Time] = BLANK(), 0, 1),
BLANK()
),
FlightTable[Direction] = "APAC",
IF(LEFT(FlightTable[Code], 1) = "V", 0, BLANK()),
FlightTable[Direction] = "AMER",
IF( FlightTable[Flight Time] = BLANK(), 0, 1),
FlightTable[Direction] = "EMEA", BLANK(),
BLANK()
)
Upvotes: 0
Reputation: 4015
Here is a measure you can use, based on your stated logic.
Use SWITCH
with TRUE
as the first argument. The first SWITCH
predicate that returns TRUE
will be used as the result for each row.
Result =
VAR _dir = SELECTEDVALUE ( 'Table'[Direction] )
VAR _code = SELECTEDVALUE ( 'Table'[Code] )
VAR _time = SELECTEDVALUE ( 'Table'[Flight Time] )
VAR _out =
SWITCH (
TRUE ,
_time = BLANK () && _dir = "AMER" , 0 , // If direction is AMER with no flight time, return 0
_dir = "EMEA" , BLANK () , // If direction is EMEA, return blank with or without flight time
_dir = "APAC" && LEFT(_code, 1) <> "V" , BLANK () , // If direction is APAC but code does not start with V, return blank
_time = BLANK () && _dir = "APAC" && LEFT(_code,1) = "V" , 0 , // When there is no flight time for APAC, and code starts with V, return 0
1 // Else 1
)
RETURN
_out
Upvotes: 0
Reputation: 1
the solution should be as follows
measue= Switch ( True(),
if(condition1,"Result1" ,
if(condition1,"Result1" ,
etc... )
this should give you what you need, because Switch in DAX acts as if & else if
Upvotes: 0