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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
AsnateKalnina
Frequent Visitor

how to handle Many to many relationship in a measure

Hi, 

I have two tables "PriceList" and "DiscountList" with following fields

 

1. PriceList:

ProcessNumber (1601, 1602, 1629, 1920...)

Type (A, B, C, D, ....)

Shipment value interval (0-50, 50-100, 100-200, 0-150, 150-500, ...)

Price for shipment

 

2.DiscountList:

Type (A, B, C, D,....)

DiscountGroup (101, 201, 301, 205, 310,...)

DiscountPercent

 

Currently the two tables ar linked with many-to-many relationship. Perhaps it should be changed and have a separate dimension table. Please suggest.

 

Eventually, in the visual part, I would like to be able to select one DiscountGroup, and see in matrix or table all records from the "PriceList" table but with applied discount (based on the selected DiscountGroup and on Type) to the field "Price for shipment".

 

The simple version would be a measure:

DiscountedPrice = [Price for shipment]*(1-[DiscountPercent]).

However, how to establish this relationship between the two tables, so that the measure understands what I need.

 

If no DiscountGroup is selected or more than one is selected, matrix/table should not show any value or show 0 or error message.

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

Hi @AsnateKalnina,

 

You may try this solution.

1 Make the relationship inactive

vcazhengmsft_0-1657008207829.png

 

2 Create a Measure like this

DiscountedPrice =
VAR selectedDiscountGroup =
    COUNTROWS ( ALLSELECTED ( DiscountList[DisountGroup] ) )
VAR discountPrice =
    CALCULATE (
        MAX ( 'PriceList'[Price for shipment] )
            * ( 1 - MAX ( 'DiscountList'[DiscountPercent] ) ),
        USERELATIONSHIP(DiscountList[Type], PriceList[Type] )
    )
VAR checkDiscountPrice =
    IF ( ISBLANK ( discountPrice ), "", discountPrice )
RETURN
    IF (
        selectedDiscountGroup = 0
            || selectedDiscountGroup > 1,
        BLANK (),
        checkDiscountPrice
    )

 

The result looks like this.

vcazhengmsft_1-1657008207830.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

3 REPLIES 3
v-cazheng-msft
Community Support
Community Support

Hi @AsnateKalnina,

 

You may try this solution.

1 Make the relationship inactive

vcazhengmsft_0-1657008207829.png

 

2 Create a Measure like this

DiscountedPrice =
VAR selectedDiscountGroup =
    COUNTROWS ( ALLSELECTED ( DiscountList[DisountGroup] ) )
VAR discountPrice =
    CALCULATE (
        MAX ( 'PriceList'[Price for shipment] )
            * ( 1 - MAX ( 'DiscountList'[DiscountPercent] ) ),
        USERELATIONSHIP(DiscountList[Type], PriceList[Type] )
    )
VAR checkDiscountPrice =
    IF ( ISBLANK ( discountPrice ), "", discountPrice )
RETURN
    IF (
        selectedDiscountGroup = 0
            || selectedDiscountGroup > 1,
        BLANK (),
        checkDiscountPrice
    )

 

The result looks like this.

vcazhengmsft_1-1657008207830.png

 

Also, attached the pbix file as reference.

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

Brilliant! 

Thank you very much!

Excellent job- a big help for me!

daXtreme
Solution Sage
Solution Sage

Hi @AsnateKalnina 

 

Could you please show some pictures of your model and data? The data can be anonymized, if you don't want to show what you've got. A picture is worth a thousand words, so they say and rightly so 🙂

 

If you want some hints... How to Get Your Question Answered Quickly (powerbi.com)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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