Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Visualization to Latest Quarter with Condition

I have a visual that needs to be filtered to the latest quarter with a condition as follows.   If the difference between current date and last date of the previous quarter is less than a month, pre...
  • v-deddai1-msft's avatar
    v-deddai1-msft
    5 years ago

    Hi Anonymous ,

     

    Please use :

     

    test =
    VAR monthafterlastquarter =
        MOD ( MONTH ( TODAY () ), 3 )
    VAR quartartoday =
        QUARTER ( TODAY () )
    VAR firstdayoflastquarter =
        IF (
            quartartoday = 1,
            CALCULATE (
                MIN ( Dim_Date1[Date] ),
                FILTER (
                    Dim_Date1,
                    Dim_Date1[Q] = 4
                        && YEAR ( Dim_Date1[Date] )
                            = YEAR ( TODAY () ) - 1
                )
            ),
            CALCULATE (
                MIN ( Dim_Date1[Date] ),
                FILTER (
                    Dim_Date1,
                    Dim_Date1[Q] = quartartoday - 1
                        && YEAR ( Dim_Date1[Date] ) = YEAR ( TODAY () )
                )
            )
        )
    RETURN
        IF (
            monthafterlastquarter >= 1,
            CALCULATE (
                [utilallocvariation],
                FILTER (
                    Dim_Date1,
                    Dim_Date1[Q] = quartartoday
                        && YEAR ( Dim_Date1[Date] ) = YEAR ( TODAY () )
                )
            ),
            CALCULATE (
                [utilallocvariation],
                FILTER (
                    Dim_Date1,
                    Dim_Date1[Date] >= firstdayoflastquarter
                        && Dim_Date1[Date] <= TODAY ()
                )
            )
        )

     

     

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

     

    Best Regards,

    Dedmon Dai