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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Venson
Frequent Visitor

Dynamic Attribute Mapping Measure

Hi everyone, Thanks for your times here !

 

I got a database as below.

ProductAttributeAAttributeBAttributeCAttributeD
ProductAText2Value3Value4Text5
ProductBText3Value1Value4Text1
ProductCText2Value3Value3Text2
ProductDText2Value3Value4Text5

 

I'd like to have a measure result table, when apply slicer filter ProductA, it will be adding one mapping Ratio column make a product compare ProductA and calculate the Mapping Ratio, if all attribute same as ProductA it will be 100%.

May please help me ? Many thanks !

 

ProductAttributeAAttributeBAttributeCAttributeDMapping Ratio
ProductAText2Value3Value4Text5100%
ProductBText3Value1Value4Text125%
ProductCText2Value3Value3Text250%
ProductDText2Value3Value4Text5100%

 

2 ACCEPTED SOLUTIONS

@Venson 
Not 100% clear. However, please try the following

1.png

Mapping Ratio = 
VAR SelectedProduct = SELECTEDVALUE ( Products[Product] )
VAR SelectedTable = 
    SELECTCOLUMNS ( 
        FILTER ( ALL ( 'Table' ), 'Table'[Product] = SelectedProduct ), 
        "A", 'Table'[AttributeA], 
        "B", 'Table'[AttributeB],
        "C", 'Table'[AttributeC],
        "D", 'Table'[AttributeD]
    )
VAR CombinedTable = CROSSJOIN ( 'Table', SelectedTable )
VAR Matches =
    SUMX ( 
        CombinedTable,
        VAR Condition1 = INT ( 'Table'[AttributeA] = [A] )
        VAR Condition2 = INT ( 'Table'[AttributeB] >= [B] )
        VAR Condition3 = INT ( 'Table'[AttributeC] >= [C] )
        VAR Condition4 = INT ( 'Table'[AttributeD] = [D] )
        RETURN
            Condition1 * ( 
                Condition2 * ( 
                    Condition1 + Condition2 + Condition3 * ( Condition3 + Condition4 )
                )
            )
    )
RETURN
    IF ( 
        HASONEVALUE ( 'Table'[Product] ),
        DIVIDE ( Matches, 4 )
    )

View solution in original post

@tamerj1 Many thanks Sir, you safe my life. I modify your formula and got what I need !!
I got over 30 attrute and thousand of products and now I can dynamically screen out and provide the mapping to user, many thanks for your time !

Mapping Ratio = 
VAR SelectedProduct = SELECTEDVALUE ( Products[Product] )
VAR SelectedTable = 
    SELECTCOLUMNS ( 
        FILTER ( ALL ( 'Table' ), 'Table'[Product] = SelectedProduct ), 
        "A", 'Table'[AttributeA], 
        "B", 'Table'[AttributeB],
        "C", 'Table'[AttributeC],
        "D", 'Table'[AttributeD]
    )
VAR CombinedTable = CROSSJOIN ( 'Table', SelectedTable )
VAR Matches =
    SUMX ( 
        CombinedTable,
        VAR Condition1 = INT ( 'Table'[AttributeA] = [A] )
        VAR Condition2 = INT ( 'Table'[AttributeB] >= [B] )
        VAR Condition3 = INT ( 'Table'[AttributeC] >= [C] )
        VAR Condition4 = INT ( 'Table'[AttributeD] = [D] )
        RETURN
            Condition1 * ( 
                Condition2 * ( 
                    Condition1 + Condition2 + Condition3 + Condition3 + Condition4
                )
            )
    )
RETURN
    IF ( 
        HASONEVALUE ( 'Table'[Product] ),
        DIVIDE ( Matches, 4 )
    )

 

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

Hi @Venson 
Please refer to attached sample file with the proposed solution

2.png1.png

Mapping Ratio = 
VAR SelectedProduct = SELECTEDVALUE ( Products[Product] )
VAR SelectedTable = 
    SELECTCOLUMNS ( 
        FILTER ( ALL ( 'Table' ), 'Table'[Product] = SelectedProduct ), 
        "A", 'Table'[AttributeA], 
        "B", 'Table'[AttributeB],
        "C", 'Table'[AttributeC],
        "D", 'Table'[AttributeD]
    )
VAR CombinedTable = CROSSJOIN ( 'Table', SelectedTable )
VAR Matches =
    SUMX ( 
        CombinedTable,
        INT ( 'Table'[AttributeA] = [A] )
            + INT ( 'Table'[AttributeB] = [B] )
            + INT ( 'Table'[AttributeC] = [C] )
            + INT ( 'Table'[AttributeD] = [D] )
    )
RETURN
    IF ( 
        HASONEVALUE ( 'Table'[Product] ), 
        Matches / 4
    )

Many thanks Sir, it's helpful !!!

Still got one problem is that some attribute content is blank, 

for example, if the filter ProductA and it doesn't have AttributeA&B,

 

Current result will become as below

ProductAttributeAAttributeBAttributeCAttributeDMapping Ratio
ProductA  Value4Text5100%
ProductBText3Value1Value4Text125%
ProductCText2Value3Text3Text20%
ProductDText2Value3Value4Text550%

 

However, I'd like to become below, when productA missing two attribute, the overall mapping ratio denominator should be ignore missing attribute then become 2.

May please help me ? appreciate !!!

ProductAttributeAAttributeBAttributeCAttributeDMapping Ratio
ProductA  Value4Text5100%
ProductBText3Value1Value4Text150%
ProductCText2Value3Text3Text20%
ProductDText2Value3Value4Text5100%

@Venson 
This is a bit more comples

1.png

Mapping Ratio = 
VAR SelectedProduct = SELECTEDVALUE ( Products[Product] )
VAR FilteredTable = FILTER ( ALL ( 'Table' ), 'Table'[Product] = SelectedProduct )
VAR SelectedTable = 
    FILTER (
        SELECTCOLUMNS ( 
            CROSSJOIN ( { "A", "B", "C", "D" }, FilteredTable ), 
            "Index", [Value],
            "Attribute", SWITCH ( [Value], "A", 'Table'[AttributeA], "B", 'Table'[AttributeB], "C", 'Table'[AttributeC], "D", 'Table'[AttributeD] )
        ),
        [Attribute] <> BLANK ( )
    )
VAR CurrentTable = 
    SELECTCOLUMNS ( 
        CROSSJOIN ( SELECTCOLUMNS ( SelectedTable, "@Index", [Index] ), 'Table' ), 
        "Index", [@Index],
        "Attribute", SWITCH ( [@Index], "A", 'Table'[AttributeA], "B", 'Table'[AttributeB], "C", 'Table'[AttributeC], "D", 'Table'[AttributeD] )
        )
VAR MatchedTable =
    INTERSECT ( CurrentTable, SelectedTable )
RETURN
    IF ( 
        HASONEVALUE ( 'Table'[Product] ),
        DIVIDE ( COUNTROWS ( MatchedTable ), COUNTROWS ( SelectedTable ) ) + 0
    )

Thank you @tamerj1  !!

it's workable, but I think I have to improve attribute missing info not cover it in the end, so I choose your first solution for current work.

 

not only mapping ratio, but also I got one charlleng now is I have to only filter out some key attribute mapping panel.

May I know what should I add in the below return portion ?

highly appreciate!!

 

RETURN
    IF ( 
        HASONEVALUE ( 'Table'[Product] ), 
        Matches / 4
    )

 

@Venson 
Please clarify further perhaps using some examples.

@tamerj1 Thank you Sir. yes, you're right, Let me put the example!

 

Database example

ProductAttributeAAttributeBAttributeCAttributeD 
ProductAText, AValue, 2Value2Text, B 
ProductBText, AValue, 1Value3Text, B 
ProductCText, AValue, 3ValueText, B 
ProductDText, AValue, 3Value4Text, C 

 

After filter A, rest of products compare to ProductA's attribute follow below conditions

Condition1: AttribueA must same & AttributeB value should larger than productA --> Count Mapping Ratio

Condition2: Same as AttributeB, if AttributeC value lager than productA treat it as mapped.

Condition3: AttributeD, text is the same treat it as mapped.

ProductAttributeAAttributeBAttributeCAttributeDMapping ratio
ProductAText, AValue, 2Value, 2Text, B100%
ProductBText, AValue, 1Value, 3Text, B(blank)
ProductCText, AValue, 3Value, 3Text, B100%
ProductDText, AValue, 3Value, 1Text, C50%

 

@Venson 
Not 100% clear. However, please try the following

1.png

Mapping Ratio = 
VAR SelectedProduct = SELECTEDVALUE ( Products[Product] )
VAR SelectedTable = 
    SELECTCOLUMNS ( 
        FILTER ( ALL ( 'Table' ), 'Table'[Product] = SelectedProduct ), 
        "A", 'Table'[AttributeA], 
        "B", 'Table'[AttributeB],
        "C", 'Table'[AttributeC],
        "D", 'Table'[AttributeD]
    )
VAR CombinedTable = CROSSJOIN ( 'Table', SelectedTable )
VAR Matches =
    SUMX ( 
        CombinedTable,
        VAR Condition1 = INT ( 'Table'[AttributeA] = [A] )
        VAR Condition2 = INT ( 'Table'[AttributeB] >= [B] )
        VAR Condition3 = INT ( 'Table'[AttributeC] >= [C] )
        VAR Condition4 = INT ( 'Table'[AttributeD] = [D] )
        RETURN
            Condition1 * ( 
                Condition2 * ( 
                    Condition1 + Condition2 + Condition3 * ( Condition3 + Condition4 )
                )
            )
    )
RETURN
    IF ( 
        HASONEVALUE ( 'Table'[Product] ),
        DIVIDE ( Matches, 4 )
    )

@tamerj1 Many thanks Sir, you safe my life. I modify your formula and got what I need !!
I got over 30 attrute and thousand of products and now I can dynamically screen out and provide the mapping to user, many thanks for your time !

Mapping Ratio = 
VAR SelectedProduct = SELECTEDVALUE ( Products[Product] )
VAR SelectedTable = 
    SELECTCOLUMNS ( 
        FILTER ( ALL ( 'Table' ), 'Table'[Product] = SelectedProduct ), 
        "A", 'Table'[AttributeA], 
        "B", 'Table'[AttributeB],
        "C", 'Table'[AttributeC],
        "D", 'Table'[AttributeD]
    )
VAR CombinedTable = CROSSJOIN ( 'Table', SelectedTable )
VAR Matches =
    SUMX ( 
        CombinedTable,
        VAR Condition1 = INT ( 'Table'[AttributeA] = [A] )
        VAR Condition2 = INT ( 'Table'[AttributeB] >= [B] )
        VAR Condition3 = INT ( 'Table'[AttributeC] >= [C] )
        VAR Condition4 = INT ( 'Table'[AttributeD] = [D] )
        RETURN
            Condition1 * ( 
                Condition2 * ( 
                    Condition1 + Condition2 + Condition3 + Condition3 + Condition4
                )
            )
    )
RETURN
    IF ( 
        HASONEVALUE ( 'Table'[Product] ),
        DIVIDE ( Matches, 4 )
    )

 

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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