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
steambucky
Helper III
Helper III

Issues with "AND", and issues with using test as a result

Hello Power BI Noob seeks help with AND statement and text…

 

This is my data:

 

 Power BI Desktop Error AND 2.png

 What I want to do have some sort of calculated column column that tells me which of the 3 groups the vaccination data fits into.

 

  • Less than 12 months since vaccinated
  • More than 12 months but less than 24 month
  • Over 24 months

 

I have part of this working with numbers

 

Vac Category =

IF([Months since last Vac] <13,

12,

IF([Months since last Vac] >12,

24,

0)

)

 

This only tells me if something is less or more that 12 months

 

What I want to do is more like this:

 

Vac Category =

IF([Months since last Vac] <13,

“Less than 12 months”,

IF([Months since last Vac] >12 AND <25,

“Between 12 and 24 months”,

“Over 24 months”)

)

 

It doesnt like the text nor the AND. 

 

Any help would be welcome.

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @steambucky

Welcome to the community 🙂

 

To solve your immediate problem, the syntax for the AND function is AND( <condition 1>, <condition 2> )

 

Also, it's always best to use preface a column with its table name i.e. TableName[ColumnName], so that columns aren't confused with measures.

 

 So you could write something like this (replace TableName with your actual table name):

 

Vac Category =
IF (
    TableName[Months since last Vac] < 13,
    "Less than 12 months",
    IF (
        AND ( TableName[Months since last Vac] > 12, TableName[Months since last Vac] < 25 ),
        "Between 12 and 24 months",
        "Over 24 months"
    )
)

 

Another suggestion for a more general solution:

https://www.daxpatterns.com/static-segmentation/

 

All the best,

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @steambucky

Welcome to the community 🙂

 

To solve your immediate problem, the syntax for the AND function is AND( <condition 1>, <condition 2> )

 

Also, it's always best to use preface a column with its table name i.e. TableName[ColumnName], so that columns aren't confused with measures.

 

 So you could write something like this (replace TableName with your actual table name):

 

Vac Category =
IF (
    TableName[Months since last Vac] < 13,
    "Less than 12 months",
    IF (
        AND ( TableName[Months since last Vac] > 12, TableName[Months since last Vac] < 25 ),
        "Between 12 and 24 months",
        "Over 24 months"
    )
)

 

Another suggestion for a more general solution:

https://www.daxpatterns.com/static-segmentation/

 

All the best,

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

You sir. are a legend. Thanks for the help 🙂

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.