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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

CASE WHEN

hello, i have been searching on how to replicate below formula in PBI:

 

CASE [Org ID]
WHEN 10665 THEN 'A'
WHEN 3004 THEN 'B'
WHEN 9966 THEN 'C'
WHEN 11026 THEN 'D'
WHEN 100 THEN 'E'
WHEN 84 THEN 'F'
WHEN 9166 THEN 'G'
WHEN 9165 THEN 'H'
WHEN 13182 THEN 'I'
ELSE ''
END

 

 

Any help pros?

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could add conditional column in power query as follows:

vyalanwumsft_0-1634189327051.png

The final output is shown below:

vyalanwumsft_1-1634189346105.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMzNVitWJVjI2MDABMywtzczADENDAyMoy8AATFtAVRhCVQAZEM2GxoYWRkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Org ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Org ID", Int64.Type}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Org ID] = 10665 then "A" else if [Org ID] = 3004 then "B" else if [Org ID] = 9966 then "C" else if [Org ID] = 11026 then "D" else if [Org ID] = 100 then "E" else if [Org ID] = 84 then "F" else if [Org ID] = 9166 then "G" else if [Org ID] = 9165 then "H" else if [Org ID] = 13182 then "G" else null)
in
    #"Added Conditional Column"

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could add conditional column in power query as follows:

vyalanwumsft_0-1634189327051.png

The final output is shown below:

vyalanwumsft_1-1634189346105.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMzNVitWJVjI2MDABMywtzczADENDAyMoy8AATFtAVRhCVQAZEM2GxoYWRkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Org ID" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Org ID", Int64.Type}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if [Org ID] = 10665 then "A" else if [Org ID] = 3004 then "B" else if [Org ID] = 9966 then "C" else if [Org ID] = 11026 then "D" else if [Org ID] = 100 then "E" else if [Org ID] = 84 then "F" else if [Org ID] = 9166 then "G" else if [Org ID] = 9165 then "H" else if [Org ID] = 13182 then "G" else null)
in
    #"Added Conditional Column"

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Use Switch

Switch ([Org ID],
10665 ,"A",
3004 ,"B",

//Add other

""

)

 

Switch-Case statement of #PowerBI: https://www.youtube.com/watch?v=gelJWktlR80&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=56

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak is it doable in power query using Custom Column?

@Anonymous , Power Query if then else

 

if [Org ID] =10665 then "A" else
if [Org ID] =10665 then "B"  else

///// Add other

 3004

 

 

nested if then else, Take care of datatype, text should be double quote

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

@amitchandak output is showing errors

@Anonymous , Try like

 

if [Org ID] = 10665 then "A" else
if [Org ID] = 3004 then "B" else
if [Org ID] = 9966 then "C" else
if [Org ID] = 11026 then "D" else
if [Org ID] = 100 then "E" else
if [Org ID] = 84 then "F" else
if [Org ID] = 9166 then "G" else
if [Org ID] = 9165 then "H" else
if [Org ID] = 13182 then "I" else ""

 

 

or share the data and error

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.