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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
Community Champion
Community Champion

#"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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.