Using Multiple If Statements in Custom Column

Joined
Nov 14, 2017
Messages
4
Reaction score
0
Points
0
Hi Folks,

I've ran into a problem that seems to require having two "If" statements within the same custom column. Here is a very simplified example of the code:

=if [Price] = 25
then [Price] * 3
else [Price]


if [Price] = 26
then [Price] * 3
else [Price]

I can't figure out the syntax needed to join these two statements together. Is this even possible to have multiple "If" statements in the same custom column? I'm by no means a computer expert, so many apologies if this is annoyingly simple.

Best,

Andrew
 
Hi Ken,

I may have over simplified my problem. Lets try this example:

Fund BFYConverted BFY
AF20181821
PT201818XX
RF201818XX
WF20181821

If Fund = Af and BFY = 2018 perform the function that converts to 1821
If Fund = PT and BFY = 2018 perform the function that converts to 18XX
If Fund = RF and BFY = 2018 perform the function that converts to 18XX
If Fund = WF and BFY = 2018 perform the funtion that converts to 1821

I've made the functions that do the converting, my problem is getting Power Query to decide when to use each one. This ends up feeding into Power Pivot, so it's kinda handy if it can all stay in one column as well. Thank you for your help. It is greatly appreciated. Had I not read your book, I would not even being attempting these types of things. I highly recommend all excel users read M is for Data Monkey, it will fundamentally change the way you use excel.

Best,

Andrew
 
Hi Andrew,

I'm not sure how your functions are set up, but providing they each take one parameter, you could try something like this:

Code:
if [Fund] = [Af] and [BFY] = 2018
    then fx1821(var1)
else if [Fund] = [PT] and [BFY] = 2018
    then fx18XX(var1)
else if [Fund] = [RF] and [BFY] = 2018
    then fx18XX(var1)
else if [Fund] = [WF] and [BFY] = 2018 
    then fx1821(var1)
else
    "none of tests were met"

(Written in browser and untested, but hopefully it gives you the structure you need)
 
Truth be told, looking at it afterwards, you could probably also get away with testing if [BFY]=2018, and then nesting a test within that:

Code:
if [BFY] = 2018then
	(
	if [Fund] = [Af]
		then fx1821(var1)
	else if [Fund] = [PT]
		then fx18XX(var1)
	else if [Fund] = [RF]
		then fx18XX(var1)
	else if [Fund] = [WF]
		then fx1821(var1)
	else
		"Fund test not met"
	)
else
	"BFY is not 2018"
 
Back
Top