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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.