Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Help ContextFilter with Time -- YTD

Hello Forum! I'm writing here with a little problem I can't seem to solve, hoping you can lend me a hand. To put it simply, I have a database with a 'Date' field and a 'Sales' field. What I would li...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

     

    Thanks for the reply from danextian , please allow me to provide another insight: 

     

     Create measure.

     

    MEASURE =
    
    VAR _min_date =
    
        CALCULATE (
    
            MIN ( 'Table'[Date] ),
    
            FILTER ( ALL ( 'Table' ), 'Table'[Year] = MAX ( 'Table'[Year] ) )
    
        )
    
    VAR _max_date =
    
        CALCULATE (
    
            MAX ( 'Table'[Date] ),
    
            FILTER ( ALL ( 'Table' ), 'Table'[Year] = MAX ( 'Table'[Year] ) )
    
        )
    
    VAR _pre =
    
        CALCULATE (
    
            SUM ( 'Table'[Sales] ),
    
            FILTER (
    
                ALL ( 'Table' ),
    
                'Table'[Date]
    
                    >= DATE ( YEAR ( _min_date ) - 1, MONTH ( _min_date ), DAY ( _min_date ) )
    
                    && 'Table'[Date]
    
                        <= DATE ( YEAR ( _max_date ) - 1, MONTH ( _max_date ), DAY ( _max_date ) )
    
            )
    
        )
    
    RETURN
    
        _pre

    If your Current Period does not refer to this, please clarify in a follow-up reply.

     

    Best Regards,

    Clara Gong

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.