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.
I need help. Can be DAX or M.
I have table1 with code and date (and more irrelevant columns).
I have table2 with the same code and date, but also a value that changes from time to time.
I need to insert a new column in table1, getting the value from table2, but only the values from the most recent date.
This new value on table2 from the most recent date might be higher or lower than the previous values.
On the example below, code A stays the same, code B goes higher from 4 to 16, but code C goes lower from 8 to 2.
It could change a lot of times, not only 2 times like this example.
See that the dates don´t match between tables. Table2 starts on Jan/01 but Table1 starts on Jan/10.
Dates and codes combined from Table1 are not distinct.
Dates and codes combined from Table2 are distinct.
Solved! Go to Solution.
Hi @Anonymous,
Try this DAX formula, please.
Column = VAR currentCode = [code] VAR currentDate = [date] VAR maxDateOfTable2 = CALCULATE ( MAX ( 'Table2'[date] ), 'Table2'[date] <= currentDate, Table2[code] = currentCode ) RETURN LOOKUPVALUE ( Table2[value], Table2[code], currentCode, Table2[date], maxDateOfTable2 )
Best Regards,
Dale
I found a way, but I don´t think it is a nice solution.
I got my table1 and duplicated it.
Remove all columns but code and date.
Then, I append it below table2, like this:
This is the new table2.
Then I created a new field which is: code+yyyy+MM+dd.
Order it ascending.
Use the Fill Down option from the Transform ribbon.
vòila!
Now I have a table like this below. Numbers in red are the Fill Down result.
Hi @Anonymous,
Try this DAX formula, please.
Column = VAR currentCode = [code] VAR currentDate = [date] VAR maxDateOfTable2 = CALCULATE ( MAX ( 'Table2'[date] ), 'Table2'[date] <= currentDate, Table2[code] = currentCode ) RETURN LOOKUPVALUE ( Table2[value], Table2[code], currentCode, Table2[date], maxDateOfTable2 )
Best Regards,
Dale
yeah! it worked! thanks a lot!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
94 | |
77 | |
65 | |
53 |
User | Count |
---|---|
145 | |
105 | |
104 | |
90 | |
63 |