Forum Discussion

MCornish's avatar
MCornish
Icon for Responsive Resident rankResponsive Resident
6 years ago
Solved

Sum where exists in another table

Ok, its probably easier to show you what im trying to create rather than try explain it   Date Promotion Value Order Value All Orders 01/01/2019  £                  952.00  £        975....
  • v-frfei-msft's avatar
    v-frfei-msft
    6 years ago

    Hi MCornish ,

     

    Sorry for mu late respond, we can create a measure as below.

    Measure = 
    VAR linkcolumn =
        VALUES ( 'Table (2)'[LinkColumn] )
    VAR ordernum =
        VALUES ( 'Table (2)'[OrderNum] )
    RETURN
        IF (
            ISFILTERED ( 'Table (2)'[PromoID] ),
            CALCULATE (
                SUM ( 'Table'[LineCost] ),
                FILTER (
                    'Table',
                    'Table'[LinkColumn] IN linkcolumn
                        && 'Table'[OrderNum] IN ordernum
                )
            ),
            BLANK ()
        )
    


    Pbix as attached as well.

     

  • MCornish's avatar
    MCornish
    6 years ago

    v-frfei-msft 

     

    With a small tweak it does what I need.

     

     

    Measure = 
    VAR linkcolumn =
        VALUES ( 'Table (2)'[LinkColumn] )
    VAR ordernum =
        VALUES ( 'Table (2)'[OrderNum] )
    RETURN
        IF (
            ISFILTERED ( 'Table (2)'[PromoID] ),
            CALCULATE (
                SUM ( 'Table'[LineCost] ),
                FILTER (
                    'Table',
                    'Table'[OrderNum] IN ordernum
                )
            ),
            BLANK ()
        )

     

     

    Basically I removed the 

    'Table'[LinkColumn] IN linkcolumn

    from the SUM.

     

    Cheers