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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
UK_User123456
Resolver I
Resolver I

If statement to check if a value is between two values and return text

Hi All,

 

Probably really simple but I am trying to return text if a number falls between two values as follows:

 

Difference
3
100
500
320
410
210

 

If one of the above falls between 0 - 365 return "Active"

 

I tried using the following DAX statement, but it wont return a text

 

IF(AND([Difference] > 0 , [difference] < 365 ), "Active" )

 

TIA 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Result = IF(and(Table1[Difference]>0 , Table1[Difference]<365),"Active",BLANK())

View solution in original post

8 REPLIES 8
JK-1
Helper I
Helper I

Is there a way to nest all these so the string can continue - with || 

IF(and(Table1[Difference]>0 , Table1[Difference]<365),"Active",BLANK())

IF(and(Table1[Difference]>365 , Table1[Difference]<500),"Active2nd",BLANK())

IF(and(Table1[Difference]>500 , Table1[Difference]<726),"Active3rd",BLANK())

 

think from reading switch would only work if true/false Boolean and here I'd want some text returned, not sure if its the > causing additional problems on multi lines or need some form of array 

Hi @UK_User123456 

 

Would a measure like this help?

Result =
	SWITCH(
		TRUE(),
		AND( 'Table1'[Difference] > 0 , 'Table1'[Difference] <= 365 ),
			"Active",
		AND( 'Table1'[Difference] > 365 , 'Table1'[Difference] <= 500 ),
			"Active2nd",
		AND( 'Table1'[Difference] > 500 , 'Table1'[Difference] <= 726 ),
			"Active3rd",
		BLANK()
	)

 

Let me know if you have any questions.



Proud to be a Super User!

daxformatter.com makes life EASIER!

Thank you so much, very helpful!

 

{in separate query} again using the IF / OR where there is only going to be 2 choices would the below work as an IF?

 

Result = IF(OR(Table1[Name]="Toni", Table1[Name]="Terry"),"12","7") these obviously would return 12 for both Toni and Terry in a true match, and 7 for any others, as false

 

but how could I write this to be: if Toni assign 12, OR if Terry assign 7 .. would it need to be split across an IN {list} query / containsstring? Just having difficulty assigning between the 2

Hi @JK-1 

 

The following 2 measures return identical results.  Additional names can be added between the braces{}.  

(I added a 3rd level for demonstration purposes.)

 

Result =
VAR _Name = MAX( 'Table1'[Name] )
RETURN
	IF(
		_Name IN { "Toni" },
		12,
		IF(
			_Name IN { "Terry" },
			7,
			IF(
				_Name IN { "Tommy" },
				6,
				0
			)
		)
	)

 

Result =
VAR _Name = MAX( 'Table1'[Name] )
RETURN
	SWITCH(
		TRUE(),
		_Name IN { "Toni" },
			12,
		_Name IN { "Terry" },
			7,
		_Name IN { "Tommy" },
			6,
		0
	)

 

I hope this helps.



Proud to be a Super User!

daxformatter.com makes life EASIER!

Thanks for both examples. Not been on for a few days but these are great. Cheers

Hi @JK-1 

 

I'm glad they helped.



Proud to be a Super User!

daxformatter.com makes life EASIER!
Anonymous
Not applicable

Result = IF(and(Table1[Difference]>0 , Table1[Difference]<365),"Active",BLANK())

This works great! I am wondering if it is possible to show the text as a label on a bar chart. It appears when you select "show as a table" but not on the actual bar chart. Any thoughts?

sakarim_0-1680631735935.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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