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
badinoff
Frequent Visitor

Better Alternative for a Nested IF with multiple Columns in a Logical Test?

The code below works, but I hear using nested IF's is not the most elegant way to go. I am not a programmer, so I need a bit of advice. Is there a better way to achieve what I am doing, or is it simple enough to keep it as is? I would have used SWITCH, but i have to run a logical test against two columns in two of those IF statements, and I don't believe SWITCH handles that. 

 

Milestone Saturation = 
	IF(Tasks[Milestones Lead (Days)] > 0 && Tasks[TaskPercentCompleted] = 100,"Complete",
		IF(Tasks[Milestones Lead (Days)] > 0 && Tasks[TaskPercentCompleted] = 0,"Late",
			IF(Tasks[Milestones Lead (Days)] = 0, "Current",
				IF(Tasks[Milestones Lead (Days)] < 0 && Tasks[Milestones Lead (Days)] >= - 3, "Upcoming",
					IF(Tasks[Milestones Lead (Days)] < -3, "Future"
		)))))

Thanks!

1 ACCEPTED SOLUTION
Peter_R
Resolver II
Resolver II

try this:

Milestone Saturation = SWITCH(
	TRUE(),
	[Milestones Lead (Days)] > 0,
		SWITCH(
			TRUE(),
			[TaskPercentCompleted] = 100, "Complete",
			[TaskPercentCompleted] = 0, "Late"
			),
	[Milestones Lead (Days)] = 0, "Current",
	[Milestones Lead (Days)] < 0,
		SWITCH(
			TRUE(),
			Tasks[Milestones Lead (Days)] >= - 3, "Upcoming",
			Tasks[Milestones Lead (Days)] < -3, "Future"
			)
)

 

View solution in original post

3 REPLIES 3
Peter_R
Resolver II
Resolver II

try this:

Milestone Saturation = SWITCH(
	TRUE(),
	[Milestones Lead (Days)] > 0,
		SWITCH(
			TRUE(),
			[TaskPercentCompleted] = 100, "Complete",
			[TaskPercentCompleted] = 0, "Late"
			),
	[Milestones Lead (Days)] = 0, "Current",
	[Milestones Lead (Days)] < 0,
		SWITCH(
			TRUE(),
			Tasks[Milestones Lead (Days)] >= - 3, "Upcoming",
			Tasks[Milestones Lead (Days)] < -3, "Future"
			)
)

 

Looks good! Thank you! I am assuming that this is a more efficient way, and that this can be called a "Nested Switch" 🙂

You could call it that.

 

I should have given credit to the idea in my first reply that it was from a posting I recalled seeing from Rob Collie - https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/

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.