Forum Discussion
Create a table using Distinct values from another table
Let's say I have two tables
| ORDERS -------- Order_Num, Material_Code, etc., etc., Ord001, 1001 Ord002, 1002 Ord003, 1003 Ord004, 1003 Ord005, 1001 | MATERIALS ------------- Material_Code, Material_Desc |
In reality my MATERIAL table is huge but I need to use Material Description as a slicer but I only want those descriptions showing that are actually in the current ORDER data, meaning each time the ORDER data is refreshed, the slicer should be refreshed. So I decided I needed a dynamic table to feed the slicer and based on the above data it would only contain:
MATERIAL_SLICER
----------------
Material_Code Material_Desc
1001 Blue
1002 Green
1003 Yellow
Now I have tried various DAX such as SUMMARIZE, SUMMARIZECOLUMNS, CALCULATETABLE but I am not getting what I want. If I was to write this in pseudo SQL it would be something like this:
SELECT Material_Code, Material_Desc
FROM Material
WHERE Material_Code in (SELECT DISTINCT Material_Code from Orders)
What is the similar DAX syntax?
\ paul
Hi Anonymous ,
Please try:
Table = FILTER('MATERIALS',[Material_Code] in VALUES(ORDERS[ Material_Code]))Final output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- v-jianboli-msftCommunity Support
Hi Anonymous ,
Please try:
Table = FILTER('MATERIALS',[Material_Code] in VALUES(ORDERS[ Material_Code]))Final output:
Best Regards,
Jianbo Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- FreemanZSuper User
hi Anonymous
try like:SlicerTable =SUMMARIZE(Orders,Materials[Material_Code],Materials[Material_Desc])- AnonymousNot applicable
Thanks but unfortunately not the solution. The way I understand the SUMMARIZE function is that it can only summarize on a field in its own dataset.
This works: slicerTable = SUMMARIZE(Orders,Orders[Materials_Code]) and returns the distinct list of codes (but no descriptions of course).
slicerTable =SUMMARIZE(Orders,Orders[Material_Code], Materials[Materials_Desc] )
fails with "The column 'Material_Desc' specified in the 'SUMMARIZE' function was not found in the input table." and any variation that puts a column from Materials in the query, fails with a similar message so your suggestion:SlicerTable =SUMMARIZE(Orders,Materials[Material_Code],Materials[Material_Desc])crashes with a similar message.I think I may have to do multiple steps!\ PauSe