Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
PauSe
Helper I
Helper I

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
1001, Blue
1002, Green
1003, Yellow
1004, Red
1005, Pink
etc, etc
etc etc

 

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

 

 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @PauSe ,

 

Please try:

Table = FILTER('MATERIALS',[Material_Code] in VALUES(ORDERS[ Material_Code]))

Final output:

vjianbolimsft_0-1672709930033.png

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.

View solution in original post

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

Hi @PauSe ,

 

Please try:

Table = FILTER('MATERIALS',[Material_Code] in VALUES(ORDERS[ Material_Code]))

Final output:

vjianbolimsft_0-1672709930033.png

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.

FreemanZ
Super User
Super User

hi @PauSe 

try like:
SlicerTable = 
SUMMARIZE(
    Orders,
    Materials[Material_Code],
    Materials[Material_Desc]
)

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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.