Merge two Power Query function into one

brawnystaff

Board Regular
Joined
Aug 9, 2012
Messages
109
Office Version
  1. 365
I have trying to consolidate two Power Query functions into one. Both query the same online resource using the same type of identifier, but, they are different in that some of the results return individual information and some results return business information. If I have a mix of both individual and business identifiers, I got error messages for the ones that are for the wrong type depending on which function I use.

The difference between the two is in the line #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers" in that the business function has a "org_name" column and the individual function has a first_name, mdl_name, last_name, and gndr_sw header. Is there some type of variable I can create to encompass all?? See below..

Power Query:
(MedStatusBus)=>
let
    Source = Json.Document(Web.Contents("https://data.cms.gov/resource/ykfi-ffzq.json?npi=" & Text.From(MedStatusBus))),
    Source1 = Source{0},
    #"Converted to Table" = Record.ToTable(Source1),
    #"Transposed Table" = Table.Transpose(#"Converted to Table"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"npi", Int64.Type}, {"pecos_asct_cntl_id", Int64.Type}, {"enrlmt_id", type text}, {"provider_type_cd", type text}, {"provider_type_desc", type text}, {"state_cd", type text}, {"org_name", type text}})
in
    #"Changed Type"

Power Query:
(MedStatusIndividual)=>
let
    Source = Json.Document(Web.Contents("https://data.cms.gov/resource/ykfi-ffzq.json?npi=" & Text.From(MedStatusIndividual))),
    Source1 = Source{0},
    #"Converted to Table" = Record.ToTable(Source1),
    #"Transposed Table" = Table.Transpose(#"Converted to Table"),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"npi", Int64.Type}, {"pecos_asct_cntl_id", Int64.Type}, {"enrlmt_id", type text}, {"provider_type_cd", type text}, {"provider_type_desc", type text}, {"state_cd", type text}, {"first_name", type text}, {"mdl_name", type text}, {"last_name", type text}, {"gndr_sw", type text}})
in
    #"Changed Type"
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Changed Type I've found hurts more than it helps especially when generated by BI without input. Do you need them formatted coming out of the function? Or can you set them up to format later.
 
Upvote 0
Delete the Change Type from each function (don't forget to update result in step) and see if it runs.
 
Upvote 0
Solution
Yes, it did run this time with no errors. The only issue is that when I expand the Table results, it does not give the business names, only the individual names (individual identifiers were listed first in the Table), but, the information provided is good enough. Not sure if there is way to fix this, but will mark as Solved. Thanks C Moore..
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,117
Members
452,545
Latest member
boybenqn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top