Forum Discussion

mhsk's avatar
mhsk
Icon for Helper II rankHelper II
7 years ago
Solved

Obtain single value from column with max values into a new column

Easy question:

 

how to get just a single value from sumQty_by_item column?

 

locationpartqtysum_qty_by_itemdateexpected result
1111106001.05.201960
2111206001.05.20190
3111306001.05.20190
12225901.05.20199
22221901.05.20190
32223901.05.20190
111152502.05.201925
211162502.05.20190
311172502.05.20190
411172502.05.20190

 

is it even possible with dax? i need it in new column as im using it in chart/as slicer etc.

  • Hi mhsk 

    I would suggest you to add an index column in query editor.Then create the column as below:

    Column =
    VAR pre_sum =
        CALCULATE (
            MAX ( 'Table'[sum] ),
            FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
        )
    RETURN
        IF (
            pre_sum <> 'Table'[sum],
            CALCULATE ( MAX ( 'Table'[sum] ), ALLEXCEPT ( 'Table', 'Table'[sum] ) ),
            0
        )
    

    Regards,

5 Replies

  • v-cherch-msft's avatar
    v-cherch-msft
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi mhsk 

    You may try below dax.

    Column =
    IF (
        [location] = 1,
        CALCULATE (
            MAX ( [sum_qty_by_item] ),
            ALLEXCEPT ( 'Table', 'Table'[sum_qty_by_item] )
        ),
        0
    )
    

    Regards,

    • mhsk's avatar
      mhsk
      Icon for Helper II rankHelper II

      thanks for a prompt reply, the thing is I don't want to connect it anyhow to location imagine my table looks:

       

      part sumexpected result
      1115050
      111500
      111500
      2226060
      222600
      222600
      33311
      33310
      33310
      4441010
      444100
      444100
      • v-cherch-msft's avatar
        v-cherch-msft
        Icon for Microsoft Employee rankMicrosoft Employee

        Hi mhsk 

        I would suggest you to add an index column in query editor.Then create the column as below:

        Column =
        VAR pre_sum =
            CALCULATE (
                MAX ( 'Table'[sum] ),
                FILTER ( 'Table', 'Table'[Index] = EARLIER ( 'Table'[Index] ) - 1 )
            )
        RETURN
            IF (
                pre_sum <> 'Table'[sum],
                CALCULATE ( MAX ( 'Table'[sum] ), ALLEXCEPT ( 'Table', 'Table'[sum] ) ),
                0
            )
        

        Regards,