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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
maxf94
Frequent Visitor

Extracting adjustment charge from one table to the other based on multiple parameters

Hello,

 

I do have the following 2 tables that I somehow need to join:

1 - Sales Table

2 - Adjustment Charge table

 

I need to extract the  correct "Adjustment Charge" and apply it to the relevant sale. In order to do that I'll need to check for multiple parameters. 

 

The "Adjustment Charge" table has got multiple values in it depending on the Quantity ordered:

Location  Sublocation  Min Max Charge

Location1 Sublocation2 0   100    10

Location1 Sublocation2 100 200   5

etc.

 

 

I'm looking for something along the lines of:


IF
Location1 = Location2
Sublocation1 = Sublocation2
Date1 <= Date2
Quantity1 <= Quantity2

THEN TotalCost1 + AdjustmentCharge2

 

 

I was hoping to do it via a Calculated Column, however I'm struggling to find a proper relationships for those tables as every one I can think of is a many-many relationship.

 

Any help would be appreciated!

1 ACCEPTED SOLUTION
maxf94
Frequent Visitor

Hello,

 

I've managed to sort my issue with the following Calculated Column:

 

Total Cost With Adjustment = 
VAR CurrentLocation = Sales[SalesLocation]
VAR CurrentSublocation = Sales[DeliveryLocation]
VAR CurrentDate = Sales[TransactionDate]
VAR CurrentQuantity = Sales[Quantity]
VAR CurrentTotalCost = Sales[Total Cost]

-- Find the matching adjustment charge
VAR MatchingAdjustment = 
    CALCULATE(
        FIRSTNONBLANK(AdjustmentTable[ChargeValue], 1),
        FILTER(
            ALL(AdjustmentTable),
            AdjustmentTable[SalesLocation] = CurrentLocation
                && AdjustmentTable[DeliveryLocation] = CurrentSublocation
                && CurrentDate >= AdjustmentTable[EffectiveDate]
                && CurrentQuantity >= AdjustmentTable[MinQuantity]
                && CurrentQuantity <= AdjustmentTable[MaxQuantity]
        )
    )

RETURN
    IF(
        ISBLANK(MatchingAdjustment),
        CurrentTotalCost,  -- No matching adjustment
        CurrentTotalCost + (CurrentQuantity * MatchingAdjustment)  -- Apply the adjustment
    )

View solution in original post

2 REPLIES 2
maxf94
Frequent Visitor

Hello,

 

I've managed to sort my issue with the following Calculated Column:

 

Total Cost With Adjustment = 
VAR CurrentLocation = Sales[SalesLocation]
VAR CurrentSublocation = Sales[DeliveryLocation]
VAR CurrentDate = Sales[TransactionDate]
VAR CurrentQuantity = Sales[Quantity]
VAR CurrentTotalCost = Sales[Total Cost]

-- Find the matching adjustment charge
VAR MatchingAdjustment = 
    CALCULATE(
        FIRSTNONBLANK(AdjustmentTable[ChargeValue], 1),
        FILTER(
            ALL(AdjustmentTable),
            AdjustmentTable[SalesLocation] = CurrentLocation
                && AdjustmentTable[DeliveryLocation] = CurrentSublocation
                && CurrentDate >= AdjustmentTable[EffectiveDate]
                && CurrentQuantity >= AdjustmentTable[MinQuantity]
                && CurrentQuantity <= AdjustmentTable[MaxQuantity]
        )
    )

RETURN
    IF(
        ISBLANK(MatchingAdjustment),
        CurrentTotalCost,  -- No matching adjustment
        CurrentTotalCost + (CurrentQuantity * MatchingAdjustment)  -- Apply the adjustment
    )
Akash_Varuna
Super User
Super User

Hi @maxf94 ,Can't you do a merge and then add a custom column for this

  • Merge Queries:

    • In Power Query, merge the "Sales Table" with the "Adjustment Charge Table" based on Location and Sublocation.
    • After merging, filter rows where:
      • SalesTable[Quantity] falls between AdjustmentChargeTable[Min] and AdjustmentChargeTable[Max].

      • SalesTable[Date] is on or before AdjustmentChargeTable[Date].

  • Add Custom Column:

    [TotalCost] + [Charge]
    You could do this in Dax also something kind of like this

 

 

Adjusted_Total_Cost =
VAR CurrentLocation = SalesTable[Location]
VAR CurrentSublocation = SalesTable[Sublocation]
VAR CurrentDate = SalesTable[Date]
VAR CurrentQuantity = SalesTable[Quantity]

RETURN
    SUMX(
        FILTER(
            'AdjustmentChargeTable',
            AdjustmentChargeTable[Location] = CurrentLocation &&
            AdjustmentChargeTable[Sublocation] = CurrentSublocation &&
            AdjustmentChargeTable[Min] <= CurrentQuantity &&
            AdjustmentChargeTable[Max] >= CurrentQuantity
        ),
        AdjustmentChargeTable[Charge]
    ) + SalesTable[TotalCost]
​

 

 

If this post helped please do give a kudos and accept this as a solution 

Thanks In Advance

 

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.

Top Solution Authors