Forum Discussion
How do I append two sources in DAX code instead of the append button?
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.
so here is the thing, it works when the columns are the same, but not when the 2nd source has different columns than the first, it gives me only the first table in the combine table.
For example:
if source 1 has account, impressions, conversionamount
if source 2 has account, impressions,revenueamount
it only gives me source 1 values, but if the column names are the same that error doesnt happen
- v-jingzhang3 years ago
Community Support
For the last column that has a different name, you want to combine them into the same column after appending or into two columns with their own names? If you want to combine them into the same column, you need to rename either of them because the Table.Combine() functions works based on the column names. If you want to have them in different columns, I think that is currently what Table.Combine() does. I haven't met the scenario that it would lose the second table that has different column names.
- shahid_tanmoy3 years ago
Helper I
I want to the same column and I want to use the name of the first source as the column header.
so possibly a code before the combine.tables line that changes the name of certain columns in the 2nd source if you can write out a code like that for me.
- v-jingzhang3 years ago
Community Support
Please try this
RenameColumns = Table.RenameColumns(#"Converted to Table2", {{"revenueamount", "conversionamount"}}), CombineTables = Table.Combine({#"Converted to Table", RenameColumns}),