Forum Discussion

mahitham's avatar
mahitham
Helper I
8 years ago
Solved

Need help to correct the expression

Hi,

 

Can any one please correct the below expression.

 

My requirement is 

I have to see Previous month New visitors count as by default in card i.e, Nov count and

when i have filtered Aug from MonthNameShort it has to show July New visitors count

when i have filtered July from MonthNameShort it has to show June New visitors count

so on.. Means by filtering current month it has to show previous month count.

 

As per below expression by default its showing November new visitors but when i have filtered Aug its showing Aug count only but i have to show July count. Please help me to correct the red color highlited section in below expression as per the requirement.

 

Previous Month New Visitors =
IF(
    ISFILTERED('Web Analytics'[MonthNameShort]),
    SUM('Web Analytics'[New Visitors]),
    CALCULATE(
        SUM('Web Analytics'[New Visitors]),
        FILTER('Web Analytics', 'Web Analytics'[MonthNumber]= Max('Web Analytics'[MonthNumber])-1
    )
))

 

Thanks in advance

 

 

 

  • try this

    Previous Month New Visitors =
    VAR PreviousMonthNr =
        MAX ( 'Web Analytics'[MonthNumber] ) - 1
    RETURN
        CALCULATE (
            SUM ( 'Web Analytics'[New Visitors] ),
            FILTER (
                ALL ( 'Web Analytics'[MonthNameShort], 'Web Analytics'[MonthNumber] ),
                'Web Analytics'[MonthNumber] = PreviousMonthNr
            )
        )

1 Reply

  • Stachu's avatar
    Stachu
    Community Champion

    try this

    Previous Month New Visitors =
    VAR PreviousMonthNr =
        MAX ( 'Web Analytics'[MonthNumber] ) - 1
    RETURN
        CALCULATE (
            SUM ( 'Web Analytics'[New Visitors] ),
            FILTER (
                ALL ( 'Web Analytics'[MonthNameShort], 'Web Analytics'[MonthNumber] ),
                'Web Analytics'[MonthNumber] = PreviousMonthNr
            )
        )