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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
raghuinpowerbi
Frequent Visitor

help me with right DAX script / any other way to visualize in PowerBI reports

In my powerbi reports, i would like to visualize the table of similar products based on the selection of one particular product.

Similarity decisions should be taken based on the columns/criteria chosen.

Say example, below is the products table.

raghuinpowerbi_0-1698357994957.png

 

CriteriaFields table is the list of column names of Product table, usually.

 

Visual report, it is like below:

raghuinpowerbi_2-1698358483458.png

 

If i choose product C and in criteria fields Color, it should list other similar products which is same color as of Product C.

if i choose product C and in criteria fields Color & Size, it should list other similar products which is of same color and size as of Product C.

 

Can you please suggest me a better way to do it ?

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_0-1698376442703.png

 

Jihwan_Kim_1-1698377422475.png

 

Color measure: = 
IF (
    HASONEVALUE ( Data[Product] ),
    VAR _productselectlist =
        VALUES ( 'Product'[Product] )
    VAR _colorselectlist =
        SUMMARIZE (
            FILTER ( ALL ( Data ), Data[Product] IN _productselectlist ),
            Data[Color]
        )
    VAR _sizeselectlist =
        SUMMARIZE (
            FILTER ( ALL ( Data ), Data[Product] IN _productselectlist ),
            Data[Size]
        )
    RETURN
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Criteria[Criteria] ) = "Color", MAXX ( FILTER ( Data, Data[Color] IN _colorselectlist ), Data[Color] ),
            SELECTEDVALUE ( Criteria[Criteria] ) = "Size", MAXX ( FILTER ( Data, Data[Size] IN _sizeselectlist ), Data[Color] ),
            MAXX (
                FILTER (
                    Data,
                    Data[Color]
                        IN _colorselectlist
                            && Data[Size] IN _sizeselectlist
                ),
                Data[Color]
            )
        )
)

 

Size measure: = 
IF (
    HASONEVALUE ( Data[Product] ),
    VAR _productselectlist =
        VALUES ( 'Product'[Product] )
    VAR _colorselectlist =
        SUMMARIZE (
            FILTER ( ALL ( Data ), Data[Product] IN _productselectlist ),
            Data[Color]
        )
    VAR _sizeselectlist =
        SUMMARIZE (
            FILTER ( ALL ( Data ), Data[Product] IN _productselectlist ),
            Data[Size]
        )
    RETURN
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Criteria[Criteria] ) = "Color", MAXX ( FILTER ( Data, Data[Color] IN _colorselectlist ), Data[Size] ),
            SELECTEDVALUE ( Criteria[Criteria] ) = "Size", MAXX ( FILTER ( Data, Data[Size] IN _sizeselectlist ), Data[Size] ),
            MAXX (
                FILTER (
                    Data,
                    Data[Color]
                        IN _colorselectlist
                            && Data[Size] IN _sizeselectlist
                ),
                Data[Size]
            )
        )
)

 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
raghuinpowerbi
Frequent Visitor

This DAX is not generalised and is not working for any number of criteria items say, if the Criteria[Criteria] has more than 2 criterias and if multiple selection happens.

Say, if Criteria[Criteria] has 5 items called "color, size, manufactured by, marketed by, cost"

 

using the same dax script given, if we chose criteria as color, size, cost , how can i adapt the script for this kind ?

raghuinpowerbi
Frequent Visitor

thats quick and perfect. thank you @Jihwan_Kim 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file if it suits your requirement.

 

Jihwan_Kim_0-1698376442703.png

 

Jihwan_Kim_1-1698377422475.png

 

Color measure: = 
IF (
    HASONEVALUE ( Data[Product] ),
    VAR _productselectlist =
        VALUES ( 'Product'[Product] )
    VAR _colorselectlist =
        SUMMARIZE (
            FILTER ( ALL ( Data ), Data[Product] IN _productselectlist ),
            Data[Color]
        )
    VAR _sizeselectlist =
        SUMMARIZE (
            FILTER ( ALL ( Data ), Data[Product] IN _productselectlist ),
            Data[Size]
        )
    RETURN
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Criteria[Criteria] ) = "Color", MAXX ( FILTER ( Data, Data[Color] IN _colorselectlist ), Data[Color] ),
            SELECTEDVALUE ( Criteria[Criteria] ) = "Size", MAXX ( FILTER ( Data, Data[Size] IN _sizeselectlist ), Data[Color] ),
            MAXX (
                FILTER (
                    Data,
                    Data[Color]
                        IN _colorselectlist
                            && Data[Size] IN _sizeselectlist
                ),
                Data[Color]
            )
        )
)

 

Size measure: = 
IF (
    HASONEVALUE ( Data[Product] ),
    VAR _productselectlist =
        VALUES ( 'Product'[Product] )
    VAR _colorselectlist =
        SUMMARIZE (
            FILTER ( ALL ( Data ), Data[Product] IN _productselectlist ),
            Data[Color]
        )
    VAR _sizeselectlist =
        SUMMARIZE (
            FILTER ( ALL ( Data ), Data[Product] IN _productselectlist ),
            Data[Size]
        )
    RETURN
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Criteria[Criteria] ) = "Color", MAXX ( FILTER ( Data, Data[Color] IN _colorselectlist ), Data[Size] ),
            SELECTEDVALUE ( Criteria[Criteria] ) = "Size", MAXX ( FILTER ( Data, Data[Size] IN _sizeselectlist ), Data[Size] ),
            MAXX (
                FILTER (
                    Data,
                    Data[Color]
                        IN _colorselectlist
                            && Data[Size] IN _sizeselectlist
                ),
                Data[Size]
            )
        )
)

 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.