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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
geoffgarcia
Helper I
Helper I

Scoring text

I have a column of types of fruit and want to add a score for each (Apple = 1, Banana = 2, Cherry = 3, etc.).

 

I've tried to create a measure thinking I could use an IF condition, but my text based fruit field doesn't return as an option.

My thought was something simple like:

If(table[fruit]="Apple") then 1

Else If(table[fruit]="Banana") then 2

Else If(table[fruit]="Cherry") then 3

 

How can I do something like this?

Thanks,
Geoff

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @geoffgarcia 

it's better to create a column with SWITCH() like

Column = 
SWITCH(table[fruit],
"Apple", 1,
"Banana", 2,
"Cherry", 3,
0
)

but if you still need a measure try

Column = 
var _fruit = MAX(table[fruit])

RETURN

SWITCH(_fruit,
"Apple", 1,
"Banana", 2,
"Cherry", 3,
0
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

2 REPLIES 2
harshnathani
Community Champion
Community Champion

Hi @geoffgarcia ,

 

Create a Calculated COlumn

 

Concept Stage Status =
SWITCH (
    TRUE (),
    table[fruit] = "Apple", 1,
    table[fruit] = "Banana", 2,
    table[fruit] = "Cherry", 3,
    BLANK ()
)

 

Regards,

Harsh Nathani

az38
Community Champion
Community Champion

Hi @geoffgarcia 

it's better to create a column with SWITCH() like

Column = 
SWITCH(table[fruit],
"Apple", 1,
"Banana", 2,
"Cherry", 3,
0
)

but if you still need a measure try

Column = 
var _fruit = MAX(table[fruit])

RETURN

SWITCH(_fruit,
"Apple", 1,
"Banana", 2,
"Cherry", 3,
0
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors