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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
KGOLSEN
Frequent Visitor

Add column with a measure or DAX?

I have a highly irritating problem. I am not able to "Get Data" from other sources to add a column to a model that I use. All I would like to do is basically perform a lookup to add a Group Name to a unique account identification number. Is this at all possible using a measure or DAX? Ex. IF ID = 1234 THEN 'GROUP NAME' = ACME INC. Please and thank you.

2 ACCEPTED SOLUTIONS
DataZoe
Microsoft Employee
Microsoft Employee

Hi @KGOLSEN ,

 

i am assuming you can't also add a calculated column as it's connected to another dataset. If you can create a calculated column then it's better you group there.

 

You can create a measure to do what you want, but you will not be able to use it in a slicer (though you can use it to filter an individual visualation in the filter pane) or on any axis/legend. I have set up this scenario before this way:

 

1. Create a measure to sort the column into groups

Group Measure =
IF (
    SELECTEDVALUE ( Table[ID] ) IN { 123456789 },
    "Group A",
    IF ( SELECTEDVALUE ( Table[ID] ) IN { 1234 }, "Group B""Group C" )
)

 

1. And at this point you realize you can't use it as an axis. So you have to make each measure filtered.

 

[Sales Group A] =
CALCULATE ( [Sales], FILTER ( Table, [Group Measure] = "Group A" ) )

 

Then you can add them each in on the values section of a visual.

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

The cleanest I can think of then is using SWITCH, something like this.

Column = 
SWITCH(
    'Table'[ID],
    1234,"Group 2",
    2345,"Group 3",
    3456,"Group 4",
    4567,"Group 5",
    5678,"Group 6",
    6789,"Group 7",
    7900,"Group 8",
    9011,"Group 9"
)

View solution in original post

7 REPLIES 7
KGOLSEN
Frequent Visitor

I was informed that what I want to do just isn't possible and the work around is just too much effort. Thank you for the suggestions and I will definetly save them as I am sure they will come in handy in the future!

DataZoe
Microsoft Employee
Microsoft Employee

Hi @KGOLSEN ,

 

i am assuming you can't also add a calculated column as it's connected to another dataset. If you can create a calculated column then it's better you group there.

 

You can create a measure to do what you want, but you will not be able to use it in a slicer (though you can use it to filter an individual visualation in the filter pane) or on any axis/legend. I have set up this scenario before this way:

 

1. Create a measure to sort the column into groups

Group Measure =
IF (
    SELECTEDVALUE ( Table[ID] ) IN { 123456789 },
    "Group A",
    IF ( SELECTEDVALUE ( Table[ID] ) IN { 1234 }, "Group B""Group C" )
)

 

1. And at this point you realize you can't use it as an axis. So you have to make each measure filtered.

 

[Sales Group A] =
CALCULATE ( [Sales], FILTER ( Table, [Group Measure] = "Group A" ) )

 

Then you can add them each in on the values section of a visual.

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

jdbuchanan71
Super User
Super User

Do you have the ID / Name pair somewhere else in your model that you can use LOOKUPVALUE to pull from?  It does not have to be joined to your destination table.

Unfortunately not. 

The cleanest I can think of then is using SWITCH, something like this.

Column = 
SWITCH(
    'Table'[ID],
    1234,"Group 2",
    2345,"Group 3",
    3456,"Group 4",
    4567,"Group 5",
    5678,"Group 6",
    6789,"Group 7",
    7900,"Group 8",
    9011,"Group 9"
)

And the 'Table' [ID] could be from an external source yes?

I thought you were trying to add a column to an existing table that already had the [ID] field in it?

Helpful resources

Announcements
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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.