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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Using IF ELSE to create a column

Hello,
My table looks like this:

allocation1allocation2allocation3rule
00017844741leader
99900064147visitor
222211008general
1111111111visitor

 

I want to create a new column called "receiver" that checks the value of the "rule" column.

 

° If rule = "leader" then receiver = allocation1
° If rule = "visitor" then receiver = allocation2
º If rule = "general" then receiver = allocation3

 

The result should look like this:

allocation1allocation2allocation3rulereceiver
00017844741leader0001
99900064147visitor0006
222211008general008
0147811166666visitor111

 

I created the following code for the column:

receiver = IF(table[rule]="leader", table[allocation1], IF(table[rule]="visitor", table[allocation2], IF(table[rule]="general", table[allocation3])))
 

but an error appears "expressions that generate variable data types cannot be used to define calculated columns"

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , this a data type issue. Check all three should have the same data type

You can try like this also

switch( true(),
table[rule]="leader", table[allocation1] &"",
table[rule]="visitor", table[allocation2] & "",
table[rule]="general", table[allocation3] & ""
)

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@Anonymous Try this: 

 

receiver = IF(table[rule]="leader", table[allocation1] & "", IF(table[rule]="visitor", table[allocation2] & "", IF(table[rule]="general", table[allocation3] & "")))

 

This will ensure that you are always returning text.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@Anonymous , this a data type issue. Check all three should have the same data type

You can try like this also

switch( true(),
table[rule]="leader", table[allocation1] &"",
table[rule]="visitor", table[allocation2] & "",
table[rule]="general", table[allocation3] & ""
)

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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