Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mahitham
Helper I
Helper I

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

 

 

 

1 ACCEPTED SOLUTION
Stachu
Community Champion
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
        )
    )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

1 REPLY 1
Stachu
Community Champion
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
        )
    )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.