Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
karelstoel
Advocate I
Advocate I

Combine columns from different datasets

Hi all,

 

I have a question about two columns from other dataset that I would like to combine. The datasets are older(1) and newer (2) data, so I can't combine them per rule. See below (pricture) the first two columns that I would like to combine and the third and fourth column that I would like to combine.

 

Thanks and have a nice weekend, hope that somebody can help me.

 

Kinds regards, Karel

Screenshot.png

 

 

 

 

3 ACCEPTED SOLUTIONS
parry2k
Super User
Super User

@karelstoel I guess these are two tables with different column names, there are many ways to do this. You can use append queries in Power Query and for this, you need to make sure the column name are the same, rename the columns and then use append and that will do it.

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

smpa01
Super User
Super User

@karelstoel  if you have a table like this called new

 

| date       | value |
|------------|-------|
| 2021-01-02 | 1000  |
| 2021-01-02 | 2000  |
| 2021-01-03 | 3000  |

  and a table like this called old

| date       | value |
|------------|-------|
| 2021-01-01 | 100   |
| 2021-01-01 | 200   |
| 2021-01-02 | 400   |

 and if you choose to create a new table through DAX that would generate all the distinct date and combined values, this is how you can do it

 

Table =
VAR _0 =
    DISTINCT ( UNION ( VALUES ( new[date] ), VALUES ( old[date] ) ) )
VAR _1 =
    ADDCOLUMNS (
        _0,
        "val",
            SUMX ( FILTER ( new, new[date] = EARLIER ( [date] ) ), new[value] )
                + SUMX ( FILTER ( old, old[date] = EARLIER ( [date] ) ), old[value] )
    )
RETURN
    _1

 

capr.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

PhilipTreacy
Super User
Super User

Hi @karelstoel 

Please see this PBIX file for a solution

If your columns have different names (as you've shown) then you could use Power Query to merge these columns using code like this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJUcEtNKipNLKpUMDIwNFfSUYIgEwtLPVMDpVgdoBoDHGoM9AwgKiBcYxMDCxM9SyMQDypqaKHgVZoD1mYJ4hpZ6hmbIcsbKziWppcWl8BVmFiagkwFKYkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Factuur.Factuurdatum = _t, Order_Date = _t, Service_Entry_Revenue_WIP = _t, Gefactureerd = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Factuur.Factuurdatum", type date}, {"Order_Date", type date}, {"Service_Entry_Revenue_WIP", type number}, {"Gefactureerd", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "DateCol", each if [Factuur.Factuurdatum] is null then [Order_Date] else [Factuur.Factuurdatum]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "NumberCol", each if [Service_Entry_Revenue_WIP] is null then [Gefactureerd] else [Service_Entry_Revenue_WIP]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"DateCol", type date}, {"NumberCol", type number}})
in
    #"Changed Type1"

Basically, it checks (for example) both date columns and takes the value from whatever column is not blank.  Then does the same for the numeric columns. 

Giving this

merge-cols.png

Note that you have a row where there is no date in either of the date columns in which case you'll get no date in the merged column too.

Regards

Phil

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

5 REPLIES 5
karelstoel
Advocate I
Advocate I

Great guys, this will help me! I am gonna check the solutions.

 

Thanks and kind regards, Karel

Anonymous
Not applicable

Hi @karelstoel ,

Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem with yours. Thank you.

Best Regards

PhilipTreacy
Super User
Super User

Hi @karelstoel 

Please see this PBIX file for a solution

If your columns have different names (as you've shown) then you could use Power Query to merge these columns using code like this

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJUcEtNKipNLKpUMDIwNFfSUYIgEwtLPVMDpVgdoBoDHGoM9AwgKiBcYxMDCxM9SyMQDypqaKHgVZoD1mYJ4hpZ6hmbIcsbKziWppcWl8BVmFiagkwFKYkFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Factuur.Factuurdatum = _t, Order_Date = _t, Service_Entry_Revenue_WIP = _t, Gefactureerd = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Factuur.Factuurdatum", type date}, {"Order_Date", type date}, {"Service_Entry_Revenue_WIP", type number}, {"Gefactureerd", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "DateCol", each if [Factuur.Factuurdatum] is null then [Order_Date] else [Factuur.Factuurdatum]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "NumberCol", each if [Service_Entry_Revenue_WIP] is null then [Gefactureerd] else [Service_Entry_Revenue_WIP]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"DateCol", type date}, {"NumberCol", type number}})
in
    #"Changed Type1"

Basically, it checks (for example) both date columns and takes the value from whatever column is not blank.  Then does the same for the numeric columns. 

Giving this

merge-cols.png

Note that you have a row where there is no date in either of the date columns in which case you'll get no date in the merged column too.

Regards

Phil

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


smpa01
Super User
Super User

@karelstoel  if you have a table like this called new

 

| date       | value |
|------------|-------|
| 2021-01-02 | 1000  |
| 2021-01-02 | 2000  |
| 2021-01-03 | 3000  |

  and a table like this called old

| date       | value |
|------------|-------|
| 2021-01-01 | 100   |
| 2021-01-01 | 200   |
| 2021-01-02 | 400   |

 and if you choose to create a new table through DAX that would generate all the distinct date and combined values, this is how you can do it

 

Table =
VAR _0 =
    DISTINCT ( UNION ( VALUES ( new[date] ), VALUES ( old[date] ) ) )
VAR _1 =
    ADDCOLUMNS (
        _0,
        "val",
            SUMX ( FILTER ( new, new[date] = EARLIER ( [date] ) ), new[value] )
                + SUMX ( FILTER ( old, old[date] = EARLIER ( [date] ) ), old[value] )
    )
RETURN
    _1

 

capr.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
parry2k
Super User
Super User

@karelstoel I guess these are two tables with different column names, there are many ways to do this. You can use append queries in Power Query and for this, you need to make sure the column name are the same, rename the columns and then use append and that will do it.

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.