Forum Discussion

spartanboy's avatar
spartanboy
Icon for Helper II rankHelper II
2 years ago
Solved

Calculate DAX for a Context

Hi,

 

Below is a table where PERIOD_1 & PERIO_2 are selected by the user, hence these are from the original table columns, the section "CHANGE" is dynamic calculation performed per user selection on P1 & P2. I am able to calculate the COST_DELTA, but need help in creating a DAX measure for MIN_COST_DELTA for each SKU, and this value should remain Static irrespective to users selection of LOCATION using filters.

 

  PERIOD 1PERIOD 2CHANGE
SKULOCATIONCOSTCOSTCOST_DELTAMIN_DELTA_COST
ABC_123A1 $    1.100 $    1.500 $           0.400 $                    (0.150)
ABC_123A2 $    1.150 $    1.200 $           0.050 $                    (0.150)
ABC_123A3 $    1.450 $    1.600 $           0.150 $                    (0.150)
ABC_123A4 $    1.200 $    1.050 $         (0.150) $                    (0.150)
ABC_123A5 $    1.000 $    1.200 $           0.200 $                    (0.150)
DEF_234B1 $    2.400 $    2.200 $         (0.200) $                    (0.400)
DEF_234B3 $    3.000 $    2.600 $         (0.400) $                    (0.400)
DEF_234B6 $    2.800 $    2.400 $         (0.400) $                    (0.400)
DEF_234B8 $    1.900 $    2.700 $           0.800 $                    (0.400)

 

  • You can try this also:

    To calculate difference in cost (measure)

    Diff Cost = sum('Table'[Period 2 COST]) - Sum('Table'[Period 1 COST])


    To calculate minimum of difference in cost in each SKU (measure):

    Min Diff Cost by SKU = 
    Minx ( FILTER( all ('Table'), 'Table'[SKU] = SELECTEDVALUE('Table'[SKU]))
           , [Diff Cost])


     Output:

     

     

     

2 Replies

  • You can try this also:

    To calculate difference in cost (measure)

    Diff Cost = sum('Table'[Period 2 COST]) - Sum('Table'[Period 1 COST])


    To calculate minimum of difference in cost in each SKU (measure):

    Min Diff Cost by SKU = 
    Minx ( FILTER( all ('Table'), 'Table'[SKU] = SELECTEDVALUE('Table'[SKU]))
           , [Diff Cost])


     Output:

     

     

     

  • Hi spartanboy ,

     

    By using minx, the following measure calculates the minimum cost difference for each SKU across all locations, ignoring any LOCATION filter set by the user.

    MIN_COST_DELTA =
    CALCULATE (
        MINX (
            ALL ( 'YourTableName'[LOCATION] ),
            -- This ignores any filters on the LOCATION column
            'YourTableName'[COST_DELTA]
        ),
        ALLEXCEPT (
            'YourTableName',
            'YourTableName'[SKU]
        ) -- This keeps filters only on SKU
    )

    Best regards,