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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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