Forum Discussion
How do I append two sources in DAX code instead of the append button?
Hi All,
I have two JSON sources.
Normally I would have to create two seperate JSON sources and append the 2nd to the first.
Can someone write me out the code to do it all in one?
Thanks!
Here is the first code, the 2nd code looks exactly the same just comes from a different system
let
Source = Json.Document(Web.Contents(" URL IS HERE ")),
(IS IT POSSIBLE TO JOIN THEM HERE, LIKE URL 1+ URL 2)
#"Converted to Table" = Table.FromRecords({Source}),
#"Expanded data" = Table.ExpandListColumn(#"Converted to Table", "data"),
#"Expanded data1" = Table.ExpandRecordColumn(#"Expanded data", "data", {"account_name"}, {"data.account_name"}),
#"Changed Type" = Table.TransformColumnTypes(#"Expanded data1",{{"data.account_name", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"data.account_name", "account_name"}})
in
#"Renamed Columns"
(OR IF THE FIRST ISINT POSSIBLE, THIS IS USUALLY WHERE THE APPEND SYNTAX IS THAT REFERS TO A DIFFERENT QUERY TABLE, IS IT POSSIBLE TO JUST UNION THE 2ND QUERY HERE)
12 Replies
- jennrattenSuper User
It looks like your source step returns a record, so you can combine Source1 and Source2 like this:
CombineRecords = Record.Combine ( { Source1, Source2 } ), #"Converted to Table" = Table.FromRecords ( CombineRecords )- shahid_tanmoyHelper I
Tried this, only gives me the second record
- v-jingzhangCommunity Support
Since the two sources are from different systems, I recommend that you remain them in two single queries. Power Query needs to treat them as from two data sources and it needs to store the credentials for these two data sources separately.
I think your final purpose is to only keep the appended result in the model, right? To meet this goal, you can use Append Queries as New to have the appended result in a third query, then unselect "Enable load" option for the two source queries. In this way, only the third "Append1" query will be loaded into the model. The two source queries will be used when appending but won't be loaded after that.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.- shahid_tanmoyHelper I
I just want one table with 2 sources unioned together in code.
I dont want to have to do 2 seperate tables and combined.- v-jingzhangCommunity Support
Ok, you may try this:
let Source1 = Json.Document(Web.Contents(" URL IS HERE 1")), Source2 = Json.Document(Web.Contents(" URL IS HERE 2")), #"Converted to Table" = Table.FromRecords({Source1}), #"Converted to Table2" = Table.FromRecords({Source2}), CombineTables = Table.Combine({#"Converted to Table", #"Converted to Table2"}), #"Expanded data" = Table.ExpandListColumn(CombineTables, "data"), #"Expanded data1" = Table.ExpandRecordColumn(#"Expanded data", "data", {"account_name"}, {"data.account_name"}), #"Changed Type" = Table.TransformColumnTypes(#"Expanded data1",{{"data.account_name", type text}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"data.account_name", "account_name"}}) in #"Renamed Columns"Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.