Forum Discussion

rod_puente's avatar
rod_puente
Helper I
1 year ago
Solved

Help with DAX Columm

Dear All

 

Please I need help with a function in DAX as a column and not as a measure that shows the sum of the last 3 months. I have this example and the yellow column should be the result of a column function by DAX:

 

 

Regards

Rodrigo P.

 

  • rod_puente 

    Ultimos 3 Meses = 
    VAR _MaxDate = 
    CALCULATE(
        MAX( 'Table'[Date] ),
        ALLEXCEPT( 'Table', 'Table'[Product])
    ) 
    VAR _Result = 
    CALCULATE(
        SUM( 'Table'[Value] ),
        DATESINPERIOD( 'Table'[Date], _MaxDate,-3,MONTH )
        ,ALLEXCEPT( 'Table','Table'[Product] )
    )
     
    RETURN
    _Result

    Regards

    sanalytics

5 Replies

  • jkrumb's avatar
    jkrumb
    Regular Visitor

    Hello, I hope I understood your request correctly

     

    Sum3LastMonths =
    VAR CurrentDate = 'YourTable'[Fecha]
    RETURN
    CALCULATE(
    SUM('YourTable'[Valor]),
    DATESINPERIOD('YourTable'[Fecha], CurrentDate, -3, MONTH)
    )

  • Joe_Barry's avatar
    Joe_Barry
    Solution Sage

    Hi rod_puente 

     

    You can try this

    Last 3 Months Sales = 
    VAR _MaxDate = CALCULATE(MAX('Table'[Fecha]), ALLEXCEPT('Table', 'Table'[Producto]))
    
    RETURN
    CALCULATE (
        SUM('Table'[Valor]),
        DATESINPERIOD('Table'[Fecha], _MaxDate, -3, MONTH),
        ALLEXCEPT('Table', 'Table'[Producto])
    )

     

    Hope this helps

    Joe

  • rod_puente 

    Ultimos 3 Meses = 
    VAR _MaxDate = 
    CALCULATE(
        MAX( 'Table'[Date] ),
        ALLEXCEPT( 'Table', 'Table'[Product])
    ) 
    VAR _Result = 
    CALCULATE(
        SUM( 'Table'[Value] ),
        DATESINPERIOD( 'Table'[Date], _MaxDate,-3,MONTH )
        ,ALLEXCEPT( 'Table','Table'[Product] )
    )
     
    RETURN
    _Result

    Regards

    sanalytics