I have two tables. First table with duplicate material numbers and an 'NR2' Column and the second table with only 1 material number and also an 'Nr' Column.
I need to display the 'NR2' from the first table 'Export' in the 'overview' table, but only the most recent (don't have a date). The last letter should be copied into the second table 'overview'. Each material number should have 2 letters at the end, hope the picture explains it. Thanks!
Export table:
Material | NR 2 |
---|---|
123 | X |
123 | Y |
123 | Z |
456 | K |
456 | L |
456 | M1 |
789 | - |
789 | A |
789 | D |
Overview table: NR 2 does not have to be the same number as NR 1
Material | NR 1 | NR2 From Export |
---|---|---|
123 | X | Z |
456 | K | M1 |
789 | D | D |
Power Query
Overview
query, merge with Export
on Material
column.Example:
let
Source = YourSourceOrPreviousStep,
#"Merged queries" = Table.NestedJoin(Source, {"Material"}, Export, {"Material"}, "Export", JoinKind.LeftOuter),
#"Expanded Export" = Table.ExpandTableColumn(Table.TransformColumns(#"Merged queries", {"Export", each Table.LastN(_, 1)}), "Export", {"NR 2"}, {"NR 2"})
in
#"Expanded Export"
DAX
If you want to do it in DAX then you will need to add an Index column to the Export
table via Power Query so that it has some form of ordering (as you don't have a date column).
In Power Query, add an Index column to your Export
table.
Then with DAX you can create a Calculated Column with:
// if there isn't a relationship
NR 2 =
CALCULATE(
MAX('Export'[NR 2]),
TOPN(1, FILTER('Export', [Material] = Overview[Material]), [Index], DESC)
)
// if there is a relationship
NR 2 =
CALCULATE(
MAX('Export'[NR 2]),
TOPN(1, CALCULATETABLE('Export'), [Index], DESC)
)