Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I have the following DAX expression in a report that extracts the level 1 category name based on prefix-matching and a known hierarchy level:
Level_1 =
VAR ThisCode = 'DimensionTable'[Code]
RETURN
CALCULATE (
MAX('DimensionTable'[Name]),
FILTER (
'DimensionTable',
'DimensionTable'[Level] = 1 &&
LEFT(ThisCode, LEN('DimensionTable'[Code])) = 'DimensionTable'[Code]
)
)I want to implement the same logic directly in Power Query as a custom column, using M language. The logic should:
Use the first characters of a code field
Match it against rows where Level = 1
Return the corresponding Name from that row
Could someone help me rewrite this logic correctly in Power Query?
Solved! Go to Solution.
You can try
= let
CurrentCode = [iec_code],
Name =
List.First(
Table.Column(
Table.SelectRows( #"Previous Step", each Text.StartsWith([iec_code], CurrentCode) and [level] = 1 ),
"name"
)
)
in
Name
You can try
= let
CurrentCode = [iec_code],
Name =
List.First(
Table.Column(
Table.SelectRows( #"Previous Step", each Text.StartsWith([iec_code], CurrentCode) and [level] = 1 ),
"name"
)
)
in
Name
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 58 | |
| 43 | |
| 41 | |
| 23 | |
| 17 |
| User | Count |
|---|---|
| 190 | |
| 121 | |
| 96 | |
| 65 | |
| 46 |