Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Saxon10
Post Prodigy
Post Prodigy

Switch multiple condition for multiple columns

 

I have 5 columns are A,B,C,D and type. Those 5 columns are contain number and text or number or text.

If column A&B and C&D are matched then return "Ok" and if column A&B and C&D are not matched then return "No" and if column A&B or C&D are blanks then return "Blanks".

If AB is blank and CD is not blanks in this case I need a result "A1". If CD is blank and AB is not blanks then I need a result "A1" as well.

 

I am applying blow mentioned DAX formula and I would like to add type column in same DAX code to get the final result.

Any advise how can I added type column in exciting DAX code or alternative way.

   

Result = var AB = [A]&[B]var CD = [C]&[D] return  SWITCH(    TRUE(),        (ISBLANK(AB) || AB = "") && (ISBLANK(CD) || CD = ""),

BLANK(),          (ISBLANK(AB) || AB = "") || (ISBLANK(CD) || CD = ""), "A1",         AB = CD, "OK",         "NO")

 

Fillter range and result:

If type is TTT then XX

if type is AA then X1

If type is BB then X2

If type is PR then X3

 

 

TYPEABCDDESIRED RESULTResult

DDAA1TT1DD1XX1NONO
DDAA1TT1DD1XX1NONO
DDAA1TT1DD1XX1NONO
TTAA1TT1DD1XX1XXNO
TTAA1TT1DD1XX1XXNO
TTAA1TT1DD1XX1XXNO
TRAA1TT2DD1XX2NONO
TRAA1TT2DD1XX2NONO
AAAA1TT2DD1XX2X1NO
AAAA1TT2DD1XX2X1NO
AAAA1TT2DD1XX2X1NO
BBBB1RR1DD1XX3X2NO
BBBB1RR1DD1XX3X2NO
BBBB1RR1DD1XX3X2NO
BBBB1RR1DD1XX3X2NO
BBBB1RR2GG1HH1X2NO
BBBB1RR2GG1HH2X2NO
BBBB1RR2GG1HH3X2NO
PR NO  X3A1
PR NO  X3A1
PR NO  X3A1
PR NO  X3A1
PRBB1RR2BB1RR2OKOK

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@Saxon10 Give this a try

 

Result2 = 
VAR AB = [A] & [B]
VAR CD = [C] & [D]
RETURN
SWITCH (
    TRUE(),
    AB = CD, "OK",
    [TYPE] = "TT","XX",
    [TYPE] = "AA","X1",
    [TYPE] = "BB","X2",
    [TYPE] = "PR","X3",
    (ISBLANK ( AB ) || AB = "" ) && ( ISBLANK ( CD ) || CD = "" ), BLANK (),
    (ISBLANK ( AB ) || AB = "" ) || ( ISBLANK ( CD ) || CD = "" ), "A1",
    "NO"
    )

 

All my results match your deisred result column.

jdbuchanan71_0-1634959216586.png

 

 

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

@Saxon10 Give this a try

 

Result2 = 
VAR AB = [A] & [B]
VAR CD = [C] & [D]
RETURN
SWITCH (
    TRUE(),
    AB = CD, "OK",
    [TYPE] = "TT","XX",
    [TYPE] = "AA","X1",
    [TYPE] = "BB","X2",
    [TYPE] = "PR","X3",
    (ISBLANK ( AB ) || AB = "" ) && ( ISBLANK ( CD ) || CD = "" ), BLANK (),
    (ISBLANK ( AB ) || AB = "" ) || ( ISBLANK ( CD ) || CD = "" ), "A1",
    "NO"
    )

 

All my results match your deisred result column.

jdbuchanan71_0-1634959216586.png

 

 

Thank you so much for your help and solution. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.