Forum Discussion
SQL->DAX: How to create a self-joined table with greater than sign in join
- 8 years ago
Hi ruut,
After a few research and test, I found a solution using M query instead DAX in your scenario.
1. Duplicate Table1 in Query Editor.
2. Create a Blank Query, and enter the following M query in Advanced Editor.
let RelativeMerge = Table.AddColumn(Table1, "RelativeJoin", (Earlier) => Table.SelectRows(Table2, each [Field1]<=Earlier[Field1] and [Field2]=Earlier[Field2] and [Field3]=Earlier[Field3])), #"Expanded RelativeJoin" = Table.ExpandTableColumn(RelativeMerge, "RelativeJoin", {"Field1", "Field4"}, {"RelativeJoin.Field1", "RelativeJoin.Field4"}), #"Reordered Columns" = Table.ReorderColumns(#"Expanded RelativeJoin",{"Field2", "Field1", "Field3", "Field4", "RelativeJoin.Field1", "RelativeJoin.Field4"}), #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Field3", "Field4"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Field1", "Field1A"}, {"RelativeJoin.Field1", "Field1B"}, {"RelativeJoin.Field4", "Summed"}}) in #"Renamed Columns"Here is the sample pbix file for your reference. :smileyhappy:
Regards
Hi ruut,
After a few research and test, I found a solution using M query instead DAX in your scenario.
1. Duplicate Table1 in Query Editor.
2. Create a Blank Query, and enter the following M query in Advanced Editor.
let
RelativeMerge = Table.AddColumn(Table1, "RelativeJoin",
(Earlier) => Table.SelectRows(Table2,
each [Field1]<=Earlier[Field1] and [Field2]=Earlier[Field2] and [Field3]=Earlier[Field3])),
#"Expanded RelativeJoin" = Table.ExpandTableColumn(RelativeMerge, "RelativeJoin", {"Field1", "Field4"}, {"RelativeJoin.Field1", "RelativeJoin.Field4"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded RelativeJoin",{"Field2", "Field1", "Field3", "Field4", "RelativeJoin.Field1", "RelativeJoin.Field4"}),
#"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Field3", "Field4"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Field1", "Field1A"}, {"RelativeJoin.Field1", "Field1B"}, {"RelativeJoin.Field4", "Summed"}})
in
#"Renamed Columns"
Here is the sample pbix file for your reference. :smileyhappy:
Regards
Hi v-ljerr-msft ,
The approach which you have suggested is greate like taek duplicate data set then join then select what ever the colulmns we requeid.
But the same thing we can achieve through DAX also . But what is the difference and which one is fater and best practice .
Please suggest.