Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi everyone,
I was trying to add another step to the result variable from this code here but kept running into the error: "The name 'result' wasn't recognized." I'd like to know how to properly correct the way I initialized the result variable if possible:
let
Source = let
CountryCleanup = (InputTable as table, ColumnName as text, optional StartRow as number) =>
let
ActualRow = if (StartRow = null) then 0 else StartRow,
result =
let
CSCountryCleanup = Table.ReplaceValue(InputTable, CSCountry{ActualRow}[CS], CSCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName}),
QTCountryCleanup = Table.ReplaceValue(CSCountryCleanup, QTCountry{ActualRow}[QT], QTCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName})
in result,
NextRow = ActualRow + 1,
OutputTable = if NextRow > (Table.RowCount(CSCountry) - 1)
then result
else @CountryCleanup(result, ColumnName, NextRow)
in OutputTable
in CountryCleanup
in
Source
The code basically tries to compare the InputTable's Country column with the CS[Country] and QT[Country] tables/columns to standardize the country names (eg: Czech Republic → Czechia, etc.). Since our dataset came from 2 different sources before merge, I am running two instances of this function (one to compare with the CS table and another to compare with the QT table) so I figured it would be better if I combined the replacements in one function.
Solved! Go to Solution.
try to change this parte of you code from:
result =
let
CSCountryCleanup = Table.ReplaceValue(InputTable, CSCountry{ActualRow}[CS], CSCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName}),
QTCountryCleanup = Table.ReplaceValue(CSCountryCleanup, QTCountry{ActualRow}[QT], QTCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName})
in result,
to:
result =
let
CSCountryCleanup = Table.ReplaceValue(InputTable, CSCountry{ActualRow}[CS], CSCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName}),
QTCountryCleanup = Table.ReplaceValue(CSCountryCleanup, QTCountry{ActualRow}[QT], QTCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName})
in QTCountryCleanup,
try to change this parte of you code from:
result =
let
CSCountryCleanup = Table.ReplaceValue(InputTable, CSCountry{ActualRow}[CS], CSCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName}),
QTCountryCleanup = Table.ReplaceValue(CSCountryCleanup, QTCountry{ActualRow}[QT], QTCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName})
in result,
to:
result =
let
CSCountryCleanup = Table.ReplaceValue(InputTable, CSCountry{ActualRow}[CS], CSCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName}),
QTCountryCleanup = Table.ReplaceValue(CSCountryCleanup, QTCountry{ActualRow}[QT], QTCountry{ActualRow}[Country], Replacer.ReplaceValue, {ColumnName})
in QTCountryCleanup,
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
10 | |
8 | |
6 | |
6 | |
6 |