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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Timaru_Golf
Advocate II
Advocate II

Adding a column using a list of distinct values from another tables column

Hi,

 

I have spent some time googling this but maybe not asking the question correctly to find the information....

 

Anyway what I am trying to do is as followings 

 

TABLE A 

From this table create a list from a Date column that containts all the unique dates.

 

Table B

In this Table I want to add a new column that containts the list generated from Table A

Col ACol BNEW COL  
Fact 1Fact 1Table A - List
Fact 2Fact 2Table A - List

 

Once I have this I can then expand the list... so I end up with a table with rows that repeats Fact 2 for all the dates and the same for Fact 2 

 

Col ACol BNEW COL
FACT 1FACT 101/01/2020
FACT 1FACT 108/01/2020
FACT 2FACT 201/01/2020
FACT 2FACT 208/01/2020

 

 

I have unsucessfully tried a number of approaches that keep coming up with errors like

Timaru_Golf_0-1593611703554.png

 

So the question is does anyone know how to do this?

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Writing code in the advanced editor is an option but it wouldn't be my first thought.

Use the 'Add Column' tab in the editor.

 

I'm not going to write the line for you as you're nearly there.

View solution in original post

6 REPLIES 6
parry2k
Super User
Super User

@Timaru_Golf use CROSSJOIN DAX function to get the expected result.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos 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.

Sorry forgot to mention this is within M code

Writing code in the advanced editor is an option but it wouldn't be my first thought.

Use the 'Add Column' tab in the editor.

 

I'm not going to write the line for you as you're nearly there.

Thanks I was over thinking it - works a treat.

 

 // Create Unique DATE column
    #"Removed Other Columns1" = Table.SelectColumns(#"Remove KEY",{"Report Date"}),
    #"Report Date" = Table.Distinct(#"Removed Other Columns1"),

// Create Fact table expanded by Dates
    #"Removed Other Columns" = Table.SelectColumns(#"Remove KEY",{"COUNTRY", "CustomerName", "CustomerNumber", "Class"}),
    #"Removed Duplicates1" = Table.Distinct(#"Removed Other Columns"),
    #"Added Custom1" = Table.AddColumn(#"Removed Duplicates1", "Custom", each #"Report Date"),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom1", "Custom", {"Report Date"}, {"Report Date"}),
HotChilli
Super User
Super User

Don't know what TableA (does it already have unique dates?)  looks like but  this should work

 

In Table B, Add a custom column with the code 

TableA[thedatecolumn]

 

Yes Table A is just a single column of unique dates.

 

Timaru_Golf_0-1593613630947.png

 

So it how I add this as a new column - my code looks like this -- having a problem with what I would put in the last line 

 

 // Create Unique DATE column
    #"Removed Other Columns1" = Table.SelectColumns(#"Remove KEY",{"Report Date"}),
    #"Report Date" = Table.Distinct(#"Removed Other Columns1"),

// Create Fact table expanded by Dates
    #"Removed Other Columns" = Table.SelectColumns(#"Remove KEY",{"COUNTRY", "CustomerName", "CustomerNumber", "Class"}),
    #"Removed Duplicates1" = Table.Distinct(#"Removed Other Columns"),
    #"Added Custom" = Table.AddColumn(XXXXXXX),

 

Thanks

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.