Forum Discussion

rqh's avatar
rqh
Frequent Visitor
2 years ago
Solved

Calculation based on Distinct Order ID

Hi everyone šŸ™‚

I want to create a measure to calculate total shipping costs, based on unique Order ID. I am using a star schema, so Order ID is not unique.
The main issue is Freight (shipping costs) is also not unique, so whenever I use SUM(), it sums everything, which is not what I want.
My attempt:
Total Freight := CALCULATE(SUM('Orders'[Freight], DISTINCT('Orders'[Order ID]) --which ended up being the same as SUM('Orders'[Freight])
I got $107K but should be getting $32K. Please help ^^'
I'll attach some screenshots.

  • rqh 
    Try  this measure:

    Total Freight = 
    
    SUMX (
        DISTINCT('Orders'[Order ID]),
        CALCULATE ( MAX( 'Orders'[Freight] ) )
    )
    

2 Replies

  • rqh 
    Try  this measure:

    Total Freight = 
    
    SUMX (
        DISTINCT('Orders'[Order ID]),
        CALCULATE ( MAX( 'Orders'[Freight] ) )
    )
    
    • rqh's avatar
      rqh
      Frequent Visitor

      Great solution, you're a godsend.