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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JoMont
Frequent Visitor

How to replace text using a lookup table without duplicating text

I have the following table

 

Medical Registration NumberDiscipline TypeFacility TypeStart DateEnd DateDiscipline Group
MED1043Primary Health
ACCHS
Primary Health4/05/202321/06/2023Community
ACCHS
MED1047Primary HealthSeveral Primary Health clinics2/11/20234/02/2024Community
MED1048Obstetrics and GynaecologyHospital8/01/202321/01/2023Obstetrics and Gynaecology and Obstetrics and Gynaecology and Gynaecology
MED1052ObstetricsHospital21/08/202329/10/2023Obstetrics and Gynaecology
MED1054Primary HealthSeveral Primary Health clinics5/02/20241/05/2024Community

 

The Discipline Group column is generated from a lookup table with the following entries (among others)

 

Detailed DisciplineDiscipline Category
Primary HealthCommunity
Primary Health ACCHSCommunity
Rural GPCommunity
GynaecologyObstetrics and Gynaecology
Gynaecology (only)Obstetrics and Gynaecology
Obstetrics & GynaecologyObstetrics and Gynaecology
Obstetrics (only)Obstetrics and Gynaecology
Obstetrics and GynaecologyObstetrics and Gynaecology

 

I have the following code that adds the Discipline Group column, based on the value in the Discipline Type column:

#"Add Discipline Group" = Table.AddColumn(#"Removed Columns", "Discipline Group", each List.Accumulate(
Table.ToRecords(Discipline_Type_Lookup), [Discipline Type],( valueToReplace, replaceOldNewRecord ) => Text.Replace( valueToReplace, replaceOldNewRecord[Detailed Discipline], replaceOldNewRecord[Discipline Category])
))
in
#"Add Discipline Group"

 

How do I get an exact match, so that "Obstetrics and Gynaecology" in the Discipline Type column does not become "Obstetrics and Gynaecology and Obstetrics and Gynaecology and Gynaecology" in the Discipline Group column, and is instead just "Obstetrics and Gynaecology"? This is also happening with "Primary Health" and many more entries in my list ("Surgery", "General Surgery" etc).

 

There are currently 141 entries in the Detailed Discipline column, so I definitely need a list function rather than manual replacements.

 

Thanks

 

1 ACCEPTED SOLUTION
SundarRaj
Super User
Super User

Hi @JoMont ,
You can use the List.PositionOf function which shall give you the exact match according to the LookUps. I'll attach the imageşof the output and the file link below. Let me know if I have understood your query correctly and in case of any doubts as well.

SundarRaj_2-1759122394030.png

SundarRaj_3-1759122445816.png


Thanks,

Sundar Rajagopalan

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

#"Add Discipline Group" = let a=List.Buffer(Table.ToRows(Table.Group(Discipline_Type_Lookup,"Discipline Category",{"n",each [Detailed Discipline]}))) in Table.AddColumn(#"Removed Columns", "Discipline Group", each List.Select(a,(x)=> List.Contains(x{1},[Discipline Type])){0}?{0}?)
in
#"Add Discipline Group"

JoMont
Frequent Visitor

Thank you, this has worked perfectly! Really appreciate your help.

SundarRaj
Super User
Super User

Hi @JoMont ,
You can use the List.PositionOf function which shall give you the exact match according to the LookUps. I'll attach the imageşof the output and the file link below. Let me know if I have understood your query correctly and in case of any doubts as well.

SundarRaj_2-1759122394030.png

SundarRaj_3-1759122445816.png


Thanks,

Sundar Rajagopalan

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors