Microsoft Certified: Power BI Data Analyst AssociatePrepare the dataMedium

A data analyst is preparing a dataset in Power Query where a column named 'ProductCost' contains numeric values representing currency. Upon inspection, some entries are found to be 'N/A' or empty strings, which are causing errors when attempting to convert the column to a decimal number type. The business requirement is to treat these non-numeric entries as zero for calculation purposes. Which Power Query transformation sequence will best handle this scenario?

  1. AAdd Conditional Column to replace 'N/A' and empty with 0, then Change Type to Decimal Number.
  2. BChange Type to Decimal Number, then Replace Errors with 0.
  3. CReplace Values 'N/A' with 0, Replace Empty with 0, then Change Type to Decimal Number.
  4. DReplace Errors with 0, then Change Type to Decimal Number.
Show answer & explanation

Correct answer: C. Replace Values 'N/A' with 0, Replace Empty with 0, then Change Type to Decimal Number.

Replacing 'N/A' and empty strings with 0 first ensures that all values are numeric or can be implicitly converted to numeric before attempting the formal type conversion. If you try to change the type first, 'N/A' and empty strings will result in errors, which then need to be handled, but it's more robust to clean the data before changing the type.

Why the other options are wrong

  • A. Adding a conditional column creates a new column, which is an unnecessary step and less direct than replacing values within the existing column.
  • B. Attempting to change type first will result in errors for 'N/A' and empty strings, which then need to be replaced. This is less efficient and assumes 'Replace Errors' handles all non-numeric cases.
  • D. Replacing errors after attempting type conversion might not catch all cases, especially empty strings which might not immediately error out but cause issues later, and it's generally better to clean known bad data before type conversion.

Robust Type Conversion

Robust type conversion in Power Query involves cleaning and transforming non-conforming data entries (e.g., text, blanks) into valid values of the target data type before applying the type conversion itself, preventing errors and ensuring data integrity.

  • Clean data BEFORE changing data type.
  • Handles specific non-numeric entries (e.g., 'N/A', empty strings).
  • Ensures successful and accurate type conversion.

Memory trick: Clean first, then convert; avoid the data dirt.

More Prepare the data questions