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
Orstenpowers
Post Patron
Post Patron

Nested IF clauses, how to deal with?

Dear all,
I hope you can help me!? I do know, what I wanna do, but I cannot write in DAX.
Please find below what the relevant formula needs to do (in prose text), but how to write it as workable formula???

 

IF
'Sold to Customer'[Global Agreement] <> BLANK
AND
(SELECTEDVALUE('Sold to Customer'[Global Agreement]) = SELECTEDVALUE('Final Ship to Customer'[Global Agreement])
THEN
'Sold to Customer'[Global Agreement]

IF
'Final Ship to Customer'[Global Agreement] = BLANK
AND
(SELECTEDVALUE('Sold to Customer'[Global Agreement]) <> SELECTEDVALUE('Final Ship to Customer'[Global Agreement])
THEN
'Sold to Customer'[Global Agreement]

IF
'Sold to Customer'[Global Agreement] = BLANK
AND
'Final Ship to Customer'[Global Agreement] <> BLANK
AND
(SELECTEDVALUE('Sold to Customer'[Global Agreement]) <> SELECTEDVALUE('Final Ship to Customer'[Global Agreement])
THEN
'Final Ship to Customer'[Global Agreement]

IF
'Sold to Customer'[Global Agreement] <> BLANK
AND
'Final Ship to Customer'[Global Agreement] <> BLANK
AND
(SELECTEDVALUE('Sold to Customer'[Global Agreement]) <> SELECTEDVALUE('Final Ship to Customer'[Global Agreement])
THEN
'Sold to Customer'[Global Agreement]

 

Hopefully some of you can help me!?

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Orstenpowers ,

 

This doesn't seem to be a problem with the formula logic, it could be a specific field in the table that is formatted incorrectly. Can you expand the "Final Ship to Customer" and "Sold to Customer" tables and replace the incorrect fields in the formulas with the correct fields in the tables.

 

If you are creating a measure, you need to add an aggregate value to the specific field in the formula, refer to the formula below:

A = 
IF (
    MAX('Sold to Customer'[Global Agreement]) <> BLANK()
        && (
            SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                = SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
        ),
    MAX('Sold to Customer'[Global Agreement]),
    IF (
        MAX('Final Ship to Customer'[Global Agreement]) = BLANK()
            && (
                SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                    <> SELECTEDVALUE ('Final Ship to Customer'[Global Agreement] )
            ),
        MAX('Sold to Customer'[Global Agreement]),
        IF (
            MAX('Sold to Customer'[Global Agreement]) = BLANK()
                && MAX('Final Ship to Customer'[Global Agreement]) <> BLANK()
                && (
                    SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                        <> SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
                ),
            MAX('Final Ship to Customer'[Global Agreement]),
            IF (
                MAX('Sold to Customer'[Global Agreement]) <> BLANK()
                    && MAX('Final Ship to Customer'[Global Agreement]) <> BLANK()
                    && (
                        SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                            <> SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
                    ),
                MAX('Sold to Customer'[Global Agreement])
            )
        )
    )
)

vhenrykmstf_0-1648709444599.pngvhenrykmstf_1-1648709644728.png


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-henryk-mstf
Community Support
Community Support

Hi @Orstenpowers ,

 

This doesn't seem to be a problem with the formula logic, it could be a specific field in the table that is formatted incorrectly. Can you expand the "Final Ship to Customer" and "Sold to Customer" tables and replace the incorrect fields in the formulas with the correct fields in the tables.

 

If you are creating a measure, you need to add an aggregate value to the specific field in the formula, refer to the formula below:

A = 
IF (
    MAX('Sold to Customer'[Global Agreement]) <> BLANK()
        && (
            SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                = SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
        ),
    MAX('Sold to Customer'[Global Agreement]),
    IF (
        MAX('Final Ship to Customer'[Global Agreement]) = BLANK()
            && (
                SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                    <> SELECTEDVALUE ('Final Ship to Customer'[Global Agreement] )
            ),
        MAX('Sold to Customer'[Global Agreement]),
        IF (
            MAX('Sold to Customer'[Global Agreement]) = BLANK()
                && MAX('Final Ship to Customer'[Global Agreement]) <> BLANK()
                && (
                    SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                        <> SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
                ),
            MAX('Final Ship to Customer'[Global Agreement]),
            IF (
                MAX('Sold to Customer'[Global Agreement]) <> BLANK()
                    && MAX('Final Ship to Customer'[Global Agreement]) <> BLANK()
                    && (
                        SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                            <> SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
                    ),
                MAX('Sold to Customer'[Global Agreement])
            )
        )
    )
)

vhenrykmstf_0-1648709444599.pngvhenrykmstf_1-1648709644728.png


If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Orstenpowers
Post Patron
Post Patron

@Samarth_18 ; Yes, sure. Please see enclosed.

Orstenpowers
Post Patron
Post Patron

2022-03-28_PBI_Community.JPG

Orstenpowers
Post Patron
Post Patron

...and it is always underlined Global Agreement, stating " Cannot find name '[Global Agreement]' "
Samarth_18
Community Champion
Community Champion

Hi @Orstenpowers ,

 

Please try this:-

A =
IF (
    'Sold to Customer'[Global Agreement] <> BLANK
        && (
            SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                = SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
        ),
    'Sold to Customer'[Global Agreement],
    IF (
        'Final Ship to Customer'[Global Agreement] = BLANK
            && (
                SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                    <> SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
            ),
        'Sold to Customer'[Global Agreement],
        IF (
            'Sold to Customer'[Global Agreement] = BLANK
                && 'Final Ship to Customer'[Global Agreement] <> BLANK
                && (
                    SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                        <> SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
                ),
            'Final Ship to Customer'[Global Agreement],
            IF (
                'Sold to Customer'[Global Agreement] <> BLANK
                    && 'Final Ship to Customer'[Global Agreement] <> BLANK
                    && (
                        SELECTEDVALUE ( 'Sold to Customer'[Global Agreement] )
                            <> SELECTEDVALUE ( 'Final Ship to Customer'[Global Agreement] )
                    ),
                'Sold to Customer'[Global Agreement]
            )
        )
    )
)

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 

Thx for your prompt reply!
I inserted your proposal and got following error message: "Wrong syntax for "&&"

 

What do I need to adjust???

@Orstenpowers , Can you please share the screenshot of the error with your code pls?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

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.