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
Paulyeo11
Impactful Individual
Impactful Individual

How to filter new customer purchase in 2020 and not purchase in 2019 ?

Hi All

I need to expression to filter those customer purchase only in 2020 and not 2019 , as indicated in below image , those i highlight in red box :-

Paulyeo11_0-1608563416120.png

My PBI file :-

https://www.dropbox.com/s/4wembkpd1ge06vj/PBT_V01015%20Buy%20in%202020%20and%20not%20buy%20in%202019...

 

Paul

2 ACCEPTED SOLUTIONS
AlB
Super User
Super User

Hi @Paulyeo11 

See it all at work in the attached file. Create this measure and place it in the visual:

 

SALES_ V2 = 
VAR sales2019_ = CALCULATE(SUM(SALES[sales]), 'Date'[Year] = 2019)
VAR sales2020_ = CALCULATE(SUM(SALES[sales]), 'Date'[Year] = 2020)
RETURN
    IF (
        NOT ISBLANK ( sales2019_ ) && ISBLANK ( sales2020_ )
            && ( SELECTEDVALUE ( 'Date'[Year] ) = 2019 || NOT ISFILTERED ( 'Date'[Year] )),
        sales2019_
    )

 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

AlB
Super User
Super User

@Paulyeo11 

Sure. Minor modification to your code:

2020_only V2 =
VAR sales2018_ =
    CALCULATE ( SUM ( SALES[sales] ), 'Date'[Year] = 2018 )
VAR sales2019_ =
    CALCULATE ( SUM ( SALES[sales] ), 'Date'[Year] = 2019 )
VAR sales2020_ =
    CALCULATE ( SUM ( SALES[sales] ), 'Date'[Year] = 2020 )
RETURN
    IF (
        NOT ISBLANK ( sales2020_ ) && ISBLANK ( sales2019_ )
            && ISBLANK ( sales2018_ )
            && (
                SELECTEDVALUE ( 'Date'[Year] ) = 2020
                    || NOT ISFILTERED ( 'Date'[Year] )
            ),
        sales2020_
    )

See it all at work in the attached file.

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

5 REPLIES 5
AlB
Super User
Super User

@Paulyeo11 

Sure. Minor modification to your code:

2020_only V2 =
VAR sales2018_ =
    CALCULATE ( SUM ( SALES[sales] ), 'Date'[Year] = 2018 )
VAR sales2019_ =
    CALCULATE ( SUM ( SALES[sales] ), 'Date'[Year] = 2019 )
VAR sales2020_ =
    CALCULATE ( SUM ( SALES[sales] ), 'Date'[Year] = 2020 )
RETURN
    IF (
        NOT ISBLANK ( sales2020_ ) && ISBLANK ( sales2019_ )
            && ISBLANK ( sales2018_ )
            && (
                SELECTEDVALUE ( 'Date'[Year] ) = 2020
                    || NOT ISFILTERED ( 'Date'[Year] )
            ),
        sales2020_
    )

See it all at work in the attached file.

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Paulyeo11
Impactful Individual
Impactful Individual

Hi AIB

Appreciated very much , you code working fine. Thank you very much.

Paul

AlB
Super User
Super User

Hi @Paulyeo11 

See it all at work in the attached file. Create this measure and place it in the visual:

 

SALES_ V2 = 
VAR sales2019_ = CALCULATE(SUM(SALES[sales]), 'Date'[Year] = 2019)
VAR sales2020_ = CALCULATE(SUM(SALES[sales]), 'Date'[Year] = 2020)
RETURN
    IF (
        NOT ISBLANK ( sales2019_ ) && ISBLANK ( sales2020_ )
            && ( SELECTEDVALUE ( 'Date'[Year] ) = 2019 || NOT ISFILTERED ( 'Date'[Year] )),
        sales2019_
    )

 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Paulyeo11
Impactful Individual
Impactful Individual

Hi AIB

 

Below expression is filter those new customer buy in 2020. Meaning those who buy in 2020 and not buy in 2019.

 

2020_only =
VAR sales2019_ = CALCULATE(SUM(SALES[sales]), 'Date'[Year] = 2019)
VAR sales2020_ = CALCULATE(SUM(SALES[sales]), 'Date'[Year] = 2020)
RETURN
IF(NOT ISBLANK(sales2020_) && ISBLANK(sales2019_) && (SELECTEDVALUE('Date'[Year]) = 2020 || NOT ISFILTERED('Date'[Year])), sales2020_)

 

May i know how to add one more condition to above expression :-

Include those customer Buy in 2020 and also not buy in 2018. And consider as 2020 new customer. ( Because i have 3 year data )

 

https://www.dropbox.com/s/erfb7vqvoro2igg/How%20to%20filter%20new%20customer%20purchase%20in%202020%...

Remark :-

Pls note that above sample data only have 2 year data , my actual data have 3 year data .

Paul Yeo

 

 

amitchandak
Super User
Super User

@Paulyeo11 , I think Nutek PTE LTD will also not come. Please find the attached file after signature 

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.