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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Harvey85
Helper I
Helper I

Add column to Table A from Table B

Hello,

I have the following tables:

 

1) Products:

IDZoneDescValue
111Spark5
121Green7
131Blue8
142Yellow10
152Red5

 

2) Categories:

IDCategoryEnd_Date
11Seed Corn1/2/2020
11Seed Pumpkin1/3/2020
11Laboratory1/4/2020
12Laboratory1/2/2020
13Seed Pumpkin1/3/2020

 

What I need to do is to add a new column in Table Products with the related End_Date (from Table Categories) from those Categories where field Category starts with "Seed" (in the other values like Laboratory the dates are not needed).

 

This would be the expected output:

IDZoneDescValueEnd_Date
111Spark51/2/2020
111Spark51/3/2020
121Green7 
131Blue81/3/2020
142Yellow10 
152Red5 

 

Do you know how could I do this?

 

Thank you!!!

1 ACCEPTED SOLUTION
_AAndrade
Super User
Super User

Hi,

If you want to do it in Power Query use this code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRU0lEC4eCCxKJsIG2qFKsDFDaCCrsXpabmAWlziLAxVNgppzQVSFlARE2ATJCGyNScnPxykBIDiIQpVCIoNQVidCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Zone = _t, Desc = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Zone", Int64.Type}, {"Desc", type text}, {"Value", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID"}, T_Categories, {"ID"}, "T_Categories", JoinKind.LeftOuter),
    #"Expanded T_Categories" = Table.ExpandTableColumn(#"Merged Queries", "T_Categories", {"Category", "End_Date"}, {"Category", "End_Date"}),
    #"Added Custom" = Table.AddColumn(#"Expanded T_Categories", "End_DateF", each if [Category] <> null and Text.Contains([Category], "Seed") then [End_Date] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Category", "End_Date"})
in
    #"Removed Columns"

You don't need the first 2 steps because you alredy have your product table.
The final result shoul be this:

_AAndrade_0-1709752472703.png

 





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




View solution in original post

2 REPLIES 2
_AAndrade
Super User
Super User

Hi,

If you want to do it in Power Query use this code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRU0lEC4eCCxKJsIG2qFKsDFDaCCrsXpabmAWlziLAxVNgppzQVSFlARE2ATJCGyNScnPxykBIDiIQpVCIoNQVidCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Zone = _t, Desc = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Zone", Int64.Type}, {"Desc", type text}, {"Value", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ID"}, T_Categories, {"ID"}, "T_Categories", JoinKind.LeftOuter),
    #"Expanded T_Categories" = Table.ExpandTableColumn(#"Merged Queries", "T_Categories", {"Category", "End_Date"}, {"Category", "End_Date"}),
    #"Added Custom" = Table.AddColumn(#"Expanded T_Categories", "End_DateF", each if [Category] <> null and Text.Contains([Category], "Seed") then [End_Date] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Category", "End_Date"})
in
    #"Removed Columns"

You don't need the first 2 steps because you alredy have your product table.
The final result shoul be this:

_AAndrade_0-1709752472703.png

 





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




amitchandak
Super User
Super User

@Harvey85 , Create new columns in Table 2

 

Value= Maxx(filter(Table1, Table2[ID] = Table1[ID]  ), Table[Value])

 

Date New = if( containsstring(table1[Category], "Seed"), [Date], blank())

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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