Forum Discussion

banks334's avatar
banks334
Frequent Visitor
7 years ago
Solved

New user: add custom column that queries data from Web Content API

Hi, I am new to power BI and need some help with a project. I thought I was trying to do something pretty straightforward, but, I've come to realize it's a bit more complicated. I am trying to add a ...
  • SteveCampbell's avatar
    7 years ago

    First, make a new parameter called NPI:

     

    Make sure you add a valid NPI number, this will be needed for testing. Also, make sure you set it as text - even through it's a number, it is going to be appended to a URL string.

     

    Then, make a new query - 
    Select New Source > Web
    Click advanced

     

    Paste in " https://npiregistry.cms.hhs.gov/api/?version=2.1&number= " to the first URL part, and have it as text (make sure you include the https://)
    The second URL part, change to parameter, and select NPI

    Now, you'll be returned a list. To get the enumeration_type , in this example:

    • Click List 
    • Click Record 
    • Convert to Table 
    • Filter Name to enumeration_type 
    • Remove Name Column

    Now, you can rename this query if you like. I called it NPIFunction.
    You now have the query ready to convert to a funtion. To do this, simply right click on the query in the left pane, and select "Create Function".

     

    Now your code is ready to be reused!
    In your query you want to add it to:

    • Go to Add Column
    • Invoke Custom Function
    • Select your Function
    • Select "Column" under NPI then select the correct Column

    Make sure you NPI column is text and not a number format

     

     

    Now it will go row by row, and run the query. You can expand the column to get the result, by clicking the symbol next to the column name.

     

    Love hearing about Power BI tips, jobs and news?
    I love to share about these - connect with me!

    Stay up to date on  
    Read my blogs on  

  • banks334's avatar
    banks334
    7 years ago

    Ok, that was great information! Next issue, I have "null" values in the NPI column. I do NOT want to remove rows because I will late rbe creating a new table of doctors that need to be reviewed by hand (nulls/errors). What is the typical method for exception handling? When I expand my custom column it stops at the first row containing a null value and throws an error. The query result in that column is an error.

     

    I am used to working in Excel or ACL where I either use if statements in my logic to check for errors, or, when running macros there are exception handling functions. I am guessing I will have to go back and "edit" the function that was created to add the error checking? Something like this: https://docs.microsoft.com/en-us/power-query/handlingerrors ?

     

    https://ibb.co/bXv92g0

    https://ibb.co/w4Dwv8m

     

    I mitigated the issue to some extent by changing all null values to zeroes. I no longer get the mismatch type exception converting null to text. However, I still have an issue with expanding the resulting table data that contains errors. Any advice on how to expand the column? I am guessing I need some kind of custom formula in that "step" in the query to ignore errors and expand the table as blank or something?