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
jasona
New Member

Using && in place of AND

Hello,

 

I have the below formula and it's not processing the last IF statement. I am getting no values back with a 1. Thank you in advance for the help.

 

Age Risk =
IF (
    'Pt Demo'[Patient Date of Birth - Copy] >= 75,
    4,
    IF (
        AND (
            'Pt Demo'[Patient Date of Birth - Copy] >= 60,
            'Pt Demo'[Patient Date of Birth - Copy] <= 74
        ),
        3,
        IF (
            AND (
                'Pt Demo'[Patient Date of Birth - Copy] >= 35,
                'Pt Demo'[Patient Date of Birth - Copy] <= 59
            ),
            2,
            IF ( 'Pt Demo'[Patient Date of Birth - Copy] <= 3410 )
        )
    )
)

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

This can be simplified to:

IF('Pt Demo'[Patient Date of Birth - Copy] >= 75,4,IF('Pt Demo'[Patient Date of Birth - Copy]>=60,3,IF('Pt Demo'[Patient Date of Birth - Copy] >= 35,2,1)))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

v-rzhou-msft
Community Support
Community Support

Hi @jasona 

I think you build a calcualted column, though your calculated column is complex, it should be correct.

Here I build a sample table "Pt Demo" with [Patient Date of Birth - Copy] column from 1 to 100. And I try your code. It works well. Please check your data model, the last if is all values <= 34 will return 1.

1.png

The logic of your code is return 4 if [Patient Date of Birth - Copy] >= 75, if [Patient Date of Birth - Copy]>=60, return 3, if [Patient Date of Birth - Copy]>=35 return 2 and others([Patient Date of Birth - Copy]<=34) return 1. There is no range to return 0.

has show you the sample code with if function. You can also try switch function to get your result.

Age Risk2 =
SWITCH (
    TRUE (),
    'Pt Demo'[Patient Date of Birth - Copy] >= 75, 4,
    'Pt Demo'[Patient Date of Birth - Copy] >= 60, 3,
    'Pt Demo'[Patient Date of Birth - Copy] >= 35, 2,
    1
)

Best Regards,

Rico Zhou

 

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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @jasona 

I think you build a calcualted column, though your calculated column is complex, it should be correct.

Here I build a sample table "Pt Demo" with [Patient Date of Birth - Copy] column from 1 to 100. And I try your code. It works well. Please check your data model, the last if is all values <= 34 will return 1.

1.png

The logic of your code is return 4 if [Patient Date of Birth - Copy] >= 75, if [Patient Date of Birth - Copy]>=60, return 3, if [Patient Date of Birth - Copy]>=35 return 2 and others([Patient Date of Birth - Copy]<=34) return 1. There is no range to return 0.

has show you the sample code with if function. You can also try switch function to get your result.

Age Risk2 =
SWITCH (
    TRUE (),
    'Pt Demo'[Patient Date of Birth - Copy] >= 75, 4,
    'Pt Demo'[Patient Date of Birth - Copy] >= 60, 3,
    'Pt Demo'[Patient Date of Birth - Copy] >= 35, 2,
    1
)

Best Regards,

Rico Zhou

 

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

Ashish_Mathur
Super User
Super User

Hi,

This can be simplified to:

IF('Pt Demo'[Patient Date of Birth - Copy] >= 75,4,IF('Pt Demo'[Patient Date of Birth - Copy]>=60,3,IF('Pt Demo'[Patient Date of Birth - Copy] >= 35,2,1)))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.