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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
gautampruthi
Helper II
Helper II

Replicate this code in Power BI

Hi,

I need to replicate this code in Power BI, How can i achive this.
"?"  refers to any single character and "*" refers to zero or more characters 

If {srs_crs.crs_code} like ["PMF*","PMP*","PDF*","PDP*","PTF*","PTP*"] then "Primary PGCE" else "" +
If {srs_crs.crs_code} like ["Q?F*","Q?P*","T?F*","T?P*"] then "Primary ITE" else "" +
If {srs_crs.crs_code} like ["PMY*","PDY*","PTY*"] then "Secondary PGCE" else "" +
If {srs_crs.crs_code} like "Q?Y*" then "Secondary ITE" else "" +
If {srs_crs.crs_code} like ["B?P4*","BAJ*","BAS*","BLS*","BSJ*","BSS*","T?S*"] then "First Degree" else "" +
If {srs_crs.crs_code} like "F*" then "Foundation Degree" else "" +
If {srs_crs.crs_code} like "AO*" then "Assessment Only" else "" +
If {srs_crs.crs_code} like "AK*" then "SKE" else "" +
If {srs_crs.crs_code} like "PS*" then "SCITT" else "" +
If {srs_crs.crs_code} like "ANP*" then "EYITT" else "" +
If {srs_crs.crs_code} like "AXS*" then "Exchange" else "" +
If {srs_crs.crs_code} like ["R*","M*"] then "Postgraduate" else "Other Undergraduate"

1 ACCEPTED SOLUTION
sroy_16
Resolver II
Resolver II

Use this in power query as a custom column and use the following custom M code.

if Text.StartsWith([crs_code], "PMF") or Text.StartsWith([crs_code], "PMP") or Text.StartsWith([crs_code], "PDF") or Text.StartsWith([crs_code], "PDP") or Text.StartsWith([crs_code], "PTF") or Text.StartsWith([crs_code], "PTP") then "Primary PGCE"
else if (Text.StartsWith([crs_code], "Q") and Text.Middle([crs_code], 1, 1) in {"F","P"}) or (Text.StartsWith([crs_code], "T") and Text.Middle([crs_code], 1, 1) in {"F","P"}) then "Primary ITE"
else if Text.StartsWith([crs_code], "PMY") or Text.StartsWith([crs_code], "PDY") or Text.StartsWith([crs_code], "PTY") then "Secondary PGCE"
else if Text.StartsWith([crs_code], "Q") and Text.Middle([crs_code], 1, 1) = "Y" then "Secondary ITE"
else if Text.StartsWith([crs_code], "B") and Text.Middle([crs_code], 1, 1) in {"P4","AJ","AS","LS","SJ","SS"} or (Text.StartsWith([crs_code], "T") and Text.Middle([crs_code], 1, 1) = "S") then "First Degree"
else if Text.StartsWith([crs_code], "F") then "Foundation Degree"
else if Text.StartsWith([crs_code], "AO") then "Assessment Only"
else if Text.StartsWith([crs_code], "AK") then "SKE"
else if Text.StartsWith([crs_code], "PS") then "SCITT"
else if Text.StartsWith([crs_code], "ANP") then "EYITT"
else if Text.StartsWith([crs_code], "AXS") then "Exchange"
else if Text.StartsWith([crs_code], "R") or Text.StartsWith([crs_code], "M") then "Postgraduate"
else "Other Undergraduate"

Try this and let me know if this works.

View solution in original post

1 REPLY 1
sroy_16
Resolver II
Resolver II

Use this in power query as a custom column and use the following custom M code.

if Text.StartsWith([crs_code], "PMF") or Text.StartsWith([crs_code], "PMP") or Text.StartsWith([crs_code], "PDF") or Text.StartsWith([crs_code], "PDP") or Text.StartsWith([crs_code], "PTF") or Text.StartsWith([crs_code], "PTP") then "Primary PGCE"
else if (Text.StartsWith([crs_code], "Q") and Text.Middle([crs_code], 1, 1) in {"F","P"}) or (Text.StartsWith([crs_code], "T") and Text.Middle([crs_code], 1, 1) in {"F","P"}) then "Primary ITE"
else if Text.StartsWith([crs_code], "PMY") or Text.StartsWith([crs_code], "PDY") or Text.StartsWith([crs_code], "PTY") then "Secondary PGCE"
else if Text.StartsWith([crs_code], "Q") and Text.Middle([crs_code], 1, 1) = "Y" then "Secondary ITE"
else if Text.StartsWith([crs_code], "B") and Text.Middle([crs_code], 1, 1) in {"P4","AJ","AS","LS","SJ","SS"} or (Text.StartsWith([crs_code], "T") and Text.Middle([crs_code], 1, 1) = "S") then "First Degree"
else if Text.StartsWith([crs_code], "F") then "Foundation Degree"
else if Text.StartsWith([crs_code], "AO") then "Assessment Only"
else if Text.StartsWith([crs_code], "AK") then "SKE"
else if Text.StartsWith([crs_code], "PS") then "SCITT"
else if Text.StartsWith([crs_code], "ANP") then "EYITT"
else if Text.StartsWith([crs_code], "AXS") then "Exchange"
else if Text.StartsWith([crs_code], "R") or Text.StartsWith([crs_code], "M") then "Postgraduate"
else "Other Undergraduate"

Try this and let me know if this works.

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.