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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.