Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have two tables joined by ID. Table 1 is just a list of unique IDs and Table 2 has multiple IDs with a note and date for each. I need to add a column to Table 1 to bring in the most recent note into the first table. Example:
Table 1:
ID |
123 |
456 |
789 |
Table 2:
ID | Date | Notes |
123 | 10/31/2019 | Note 3 |
123 | 10/30/2019 | Note 2 |
123 | 8/20/2019 | Note 1 |
456 | 6/1/2019 | Note 4 |
456 | 5/30/2019 | Note 3 |
456 | 5/6/2019 | Note 2 |
456 | 5/1/2019 | Note 1 |
789 | 10/8/2019 | Note 1 |
Desired result in Table 1:
ID | Note |
123 | Note 3 |
456 | Note 4 |
789 | Note1 |
Solved! Go to Solution.
Here you go, FINALLY! 2 Custom Columns required...
Max Date = CALCULATE(MAX(Table2[Date])) ** Make this one First, to make Part 2 below easier. **
** You don't have to display Max Date, it just has to be another Custom Column on the table. **
Table 1:
ID | Max Date | Column 2 |
123 | 10/31/2019 0:00 | Note 3 |
456 | 11/2/2019 0:00 | Note1a - Dup |
559 | 11/1/2019 0:00 | NEW NOTE |
789 | 10/31/2019 0:00 | Note5 |
Table 2:
ID | Date | Notes |
123 | 8/20/2019 0:00 | Note 1 |
123 | 10/30/2019 0:00 | Note 2 |
123 | 10/31/2019 0:00 | Note 3 |
456 | 5/1/2019 0:00 | Note 1 |
456 | 5/6/2019 0:00 | Note 2 |
456 | 5/30/2019 0:00 | Note 3 |
456 | 6/1/2019 0:00 | Note 4 |
456 | 10/31/2019 0:00 | Note1a |
456 | 11/2/2019 0:00 | Note1a - Dup |
559 | 11/1/2019 0:00 | NEW NOTE |
789 | 10/8/2019 0:00 | Note 1 |
789 | 10/31/2019 0:00 | Note5 |
Proud to give back to the community!
Thank You!
Create a New Column on Table 1 and here's your code...
Proud to give back to the community!
Thank You!
Thanks! I see what this is trying to do, but I get an "A table of multiple values was supplied where a single value was expected" error. I've verified that my real Table 1 has unique IDs whereas Table 2 has multiple.
I went back and added duplicate dates on my Table 2 per ID, but still didn't get the error you mentioned. Do you have any way to cleanse and post your data tables?
FOrrest
Table1
ID | NewestNote |
123 | Note 3 |
456 | Note1a |
789 | Note5 |
Table 2
ID | Date | Notes |
123 | 8/20/2019 0:00 | Note 1 |
123 | 10/30/2019 0:00 | Note 2 |
123 | 10/31/2019 0:00 | Note 3 |
456 | 5/1/2019 0:00 | Note 1 |
456 | 5/6/2019 0:00 | Note 2 |
456 | 5/30/2019 0:00 | Note 3 |
456 | 6/1/2019 0:00 | Note 4 |
456 | 10/31/2019 0:00 | Note1a |
789 | 10/8/2019 0:00 | Note 1 |
789 | 10/31/2019 0:00 | Note5 |
Proud to give back to the community!
Thank You!
My data will be hard to cleanse to send, as it is a large dataset. I think I found the problem, although I don't know how to solve it. My date column in Table2 could have the same date/time for the same ID. If you change the date in the last line of your sample date for ID 789 to 10/8/2019 0:00 so that both 789 records have the same date you can recreate the error. Are you aware of any way around that?
Yep, that did cause me to duplicate your error. When you have ID & Date Duplicates, are the Notes the same as well? (Then you can freely select any value since they are all the same?)
Or, are the notes different for the ID/Date Duplicates? In this case, what logic should be used to select the First / Last Note, or do you want an error message saying 'Duplicate' or something else to populate?
Proud to give back to the community!
Thank You!
It would be possible to have the same note/date/ID, but I'd say that would probably never happen.
So, for Same ID/Dates, but different Notes, do you want to see BOTH Notes, or what logic should be used to select one of the Notes?
Proud to give back to the community!
Thank You!
This scenario would be so rare that it doesn't really matter. It could return either one or both. Whichever one is easier.
Create a NEW Column on Table 1
Proud to give back to the community!
Thank You!
That only brought back a result for the first record:
ID | Column |
123 | Note 3 |
456 | |
789 |
Are there more columns involved that might be causing issues? Did you create the new Column off Table 1? My Table 1 only has ID's, and Table 2 only has ID, Date, & Notes. Here's my code for the Custom Column off Table 1. Can you make this work as is below outside your data set? (Double check you are filtering Tables 2 where Table 1 ID = Table **2** ID.)
Table 1:
ID | Column |
123 | Note 3 |
456 | Note1a |
789 | Note5 |
Table 2:
ID | Date | Notes |
123 | 8/20/2019 0:00 | Note 1 |
123 | 10/30/2019 0:00 | Note 2 |
123 | 10/31/2019 0:00 | Note 3 |
456 | 5/1/2019 0:00 | Note 1 |
456 | 5/6/2019 0:00 | Note 2 |
456 | 5/30/2019 0:00 | Note 3 |
456 | 6/1/2019 0:00 | Note 4 |
456 | 10/31/2019 0:00 | Note1a |
456 | 10/31/2019 0:00 | Note1a - Dup |
789 | 10/8/2019 0:00 | Note 1 |
789 | 10/31/2019 0:00 | Note5 |
Proud to give back to the community!
Thank You!
That is so odd. When it didn't work in my real dataset I thought it may be something else messing it up, so tried it with my sample date. As you can see, the formula is a copy and past of yours, but my results don't match up.
....? Assuming you have a 1 to many relationship between Table 1 & Table 2. Other than that, I hope someone else picks up this thread who might have some other ideas?
FOrrest
Proud to give back to the community!
Thank You!
I do. Thanks for trying to help! There must be something weird going on that someone else can hopefully answer.
I think I see what I did wrong... all of my Notes had 10/31 as dates... DOH! Let me poke at it more...
Proud to give back to the community!
Thank You!
Here you go, FINALLY! 2 Custom Columns required...
Max Date = CALCULATE(MAX(Table2[Date])) ** Make this one First, to make Part 2 below easier. **
** You don't have to display Max Date, it just has to be another Custom Column on the table. **
Table 1:
ID | Max Date | Column 2 |
123 | 10/31/2019 0:00 | Note 3 |
456 | 11/2/2019 0:00 | Note1a - Dup |
559 | 11/1/2019 0:00 | NEW NOTE |
789 | 10/31/2019 0:00 | Note5 |
Table 2:
ID | Date | Notes |
123 | 8/20/2019 0:00 | Note 1 |
123 | 10/30/2019 0:00 | Note 2 |
123 | 10/31/2019 0:00 | Note 3 |
456 | 5/1/2019 0:00 | Note 1 |
456 | 5/6/2019 0:00 | Note 2 |
456 | 5/30/2019 0:00 | Note 3 |
456 | 6/1/2019 0:00 | Note 4 |
456 | 10/31/2019 0:00 | Note1a |
456 | 11/2/2019 0:00 | Note1a - Dup |
559 | 11/1/2019 0:00 | NEW NOTE |
789 | 10/8/2019 0:00 | Note 1 |
789 | 10/31/2019 0:00 | Note5 |
Proud to give back to the community!
Thank You!
Woohoo! Got it to work in my sample and actual datasets! I actually already had a max date column so this worked out perfectly. Thanks so much for all of your help on this!
User | Count |
---|---|
79 | |
74 | |
44 | |
32 | |
28 |
User | Count |
---|---|
100 | |
93 | |
52 | |
50 | |
48 |