DAX lookupValue with date filter

Lars1

Board Regular
Joined
Feb 3, 2021
Messages
158
Office Version
  1. 365
Platform
  1. Windows
Hi

How to lookup a value in a table and only take the latest value ?
I have this table:
1639647114714.png


And i would like to create a new table with this result:
The result in the new table should only be the latest/newest value on each "Code".
1639647335382.png


Can anyone help with a DAX solution to this ?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Use Power Query for this result
Book2
ABCDEFG
1CodeStartDateKursCodeMaxDateTable1 (2).Kurs
2NOK10/1/2021100NOK10/1/2021100
3NOK5/5/2021200SEK10/5/2021300
4NOK6/6/2021300
5SEK6/7/2021100
6SEK5/4/2021200
7SEK10/5/2021300
Sheet1


In your table find the Max Date
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"StartDate", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Code"}, {{"MaxDate", each List.Max([StartDate]), type nullable date}})
in
    #"Grouped Rows"
Merge your query back onto itself
Power Query:
let
    Source = Table.NestedJoin(Table1, {"Code", "MaxDate"}, #"Table1 (2)", {"Code", "StartDate"}, "Table1 (2)", JoinKind.LeftOuter),
    #"Expanded Table1 (2)" = Table.ExpandTableColumn(Source, "Table1 (2)", {"Kurs"}, {"Table1 (2).Kurs"})
in
    #"Expanded Table1 (2)"
 
Upvote 0
Use Power Query for this result
Book2
ABCDEFG
1CodeStartDateKursCodeMaxDateTable1 (2).Kurs
2NOK10/1/2021100NOK10/1/2021100
3NOK5/5/2021200SEK10/5/2021300
4NOK6/6/2021300
5SEK6/7/2021100
6SEK5/4/2021200
7SEK10/5/2021300
Sheet1


In your table find the Max Date
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"StartDate", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Code"}, {{"MaxDate", each List.Max([StartDate]), type nullable date}})
in
    #"Grouped Rows"
Merge your query back onto itself
Power Query:
let
    Source = Table.NestedJoin(Table1, {"Code", "MaxDate"}, #"Table1 (2)", {"Code", "StartDate"}, "Table1 (2)", JoinKind.LeftOuter),
    #"Expanded Table1 (2)" = Table.ExpandTableColumn(Source, "Table1 (2)", {"Kurs"}, {"Table1 (2).Kurs"})
in
    #"Expanded Table1 (2)"
Hi

Thank you so much for your solution.
I am looking for a solution in DAX though :-)
 
Upvote 0
This could be your calculated column

Power Query:
=CALCULATE (
   MAX ( Table1[Starting Date] );
        ALLEXCEPT ( Table1; Table1[Code] ))
 
Upvote 0
This could be your calculated column

Power Query:
=CALCULATE (
   MAX ( Table1[Starting Date] );
        ALLEXCEPT ( Table1; Table1[Code] ))
Thanks for your input.

I still need this result:
1639647335382-png.53511


And your solution comes with an error:
A single value for the 'Starting Date' column in the 'Currency Exchange Rate' table cannot be determined. This can happen when a measurement formula refers to a column that contains many values without specifying a sum function such as min, max, count or sum to form a single result.
 
Upvote 0
Try this:

1. In Power Pivot for Excel create variable:
MaxStartDate:=MAX(Table1[StartDate])
2. From Power Pivot for Excel insert new Pivot Table
3. Insert columns (Code, StartDate, Kurs) in Rows Area
4. In Report Layout choice Show in Tabular Form
5. Disable Subtotals and Grand Totals
6. Sort StartDate: Newest to Oldest
7. Add filter "Top 10 Filter" Items 1 by MaxStartDate
 
Upvote 0
Try this:

1. In Power Pivot for Excel create variable:
MaxStartDate:=MAX(Table1[StartDate])
2. From Power Pivot for Excel insert new Pivot Table
3. Insert columns (Code, StartDate, Kurs) in Rows Area
4. In Report Layout choice Show in Tabular Form
5. Disable Subtotals and Grand Totals
6. Sort StartDate: Newest to Oldest
7. Add filter "Top 10 Filter" Items 1 by MaxStartDate
Thank you for your solution.
it seems like i have not been very clear in my request...
I need a soluition in DAX and NOT PowerPivot.
 
Upvote 0
DAX Solution:

Code:
NewTable =
FILTER (
    'Table',
    'Table'[StartDate] = CALCULATE ( MAX ( 'Table'[StartDate] ), ALLEXCEPT ( 'Table', 'Table'[Code] )))
 
Upvote 0
Solution

Forum statistics

Threads
1,223,681
Messages
6,173,815
Members
452,535
Latest member
berdex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top