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

DAX

I'm trying to create a column that assigns a value based on following table.  Getting DAX error.  If I reference AI table and location is x then value is value. Any help would be greatly appreciated.  

AI Table       Quest          New Ideal Column 
AI Record    Location       Weight Value

 

Weight = SWITCH ( TRUE(),
'AI'[quest] = "California", 6,
'AI'[quest] = "Nebraska", 3,
'AI'[quest] = "Florida", 10,
'AI'[quest] = "Texas", 8,
'AI'[quest] = "Georgia",3,
'AI'[quest] = "Newyork", 10,
'AI'[quest] = "Maryland", 4,
'AI'[quest] = "Ohio", 8,
'AI'[quest] = "Alabama", 10,
)

2 ACCEPTED SOLUTIONS
az38
Community Champion
Community Champion

Hi @kingrob01 

you've got an exessive last common ","

anyway, you can try to do it more easy

Weight = SWITCH ( 'AI'[quest],
"California", 6,
"Nebraska", 3,
"Florida", 10,
"Texas", 8,
"Georgia",3,
"Newyork", 10,
"Maryland", 4,
"Ohio", 8,
"Alabama", 10,
"Undefined"
)

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

View solution in original post

Pragati11
Super User
Super User

Hi @kingrob01 ,

 

In your DAX expression, you have got an extra "," in the end. Just remove it and use the following:

 

Weight = SWITCH ( TRUE(),
'AI'[quest] = "California", 6,
'AI'[quest] = "Nebraska", 3,
'AI'[quest] = "Florida", 10,
'AI'[quest] = "Texas", 8,
'AI'[quest] = "Georgia",3,
'AI'[quest] = "Newyork", 10,
'AI'[quest] = "Maryland", 4,
'AI'[quest] = "Ohio", 8,
'AI'[quest] = "Alabama", 10
)

 

This will work.

 

Thanks.

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

2 REPLIES 2
Pragati11
Super User
Super User

Hi @kingrob01 ,

 

In your DAX expression, you have got an extra "," in the end. Just remove it and use the following:

 

Weight = SWITCH ( TRUE(),
'AI'[quest] = "California", 6,
'AI'[quest] = "Nebraska", 3,
'AI'[quest] = "Florida", 10,
'AI'[quest] = "Texas", 8,
'AI'[quest] = "Georgia",3,
'AI'[quest] = "Newyork", 10,
'AI'[quest] = "Maryland", 4,
'AI'[quest] = "Ohio", 8,
'AI'[quest] = "Alabama", 10
)

 

This will work.

 

Thanks.

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

az38
Community Champion
Community Champion

Hi @kingrob01 

you've got an exessive last common ","

anyway, you can try to do it more easy

Weight = SWITCH ( 'AI'[quest],
"California", 6,
"Nebraska", 3,
"Florida", 10,
"Texas", 8,
"Georgia",3,
"Newyork", 10,
"Maryland", 4,
"Ohio", 8,
"Alabama", 10,
"Undefined"
)

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

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.

Top Solution Authors