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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
mb0307
Responsive Resident
Responsive Resident

Filter on calculated column- customers not bought

Hi 

 

I want to find the customers who didnt buy in these category. 

 

"3 to 6 months"

"6 to 12 months"

"More then 12 Months"

" Recently"

 

I have made a calculated column , but its not showing the correct result. 1 customer should fall in 1category only and should latest 1 record.

But for me e.g. "A" customer is shown when i select "More then 12 Months" filter or " Recently" filter.

 

Trans    
CustomerInv AmountInv dateCurrent calculated Column Customer not BoughtResult sould be
A10003/01/2019more then 12 monthsRecently
A20020/06/2020RecentlyRecently
B40001/08/2019more then 12 monthsmore then 12 months
C20006/05/20203 to 6 months3 to 6 months
D45007/04/20203to 6 months3to 6 months
E30012/09/2019more then 12 months3to 6 months
T10001/01/20206 to 12 months6 to 12 months
D30015/02/2019more then 12 months3to 6 months
E50003/04/20203to 6 months3to 6 months
R10008/07/2020RecentlyRecently

 

Measure

Last sale date = CALCULATE(MAXX(Trans[INV DATE],FILTERS(Cus[Customer]),ALL(Dates[Date]))

 

calculated column

Customer Not Bought =
VAR Mnth3 = DATE(YEAR(TODAY(),MONTH(TODAY())-3,DAY(TODAY()))
VAR Mnth6 = DATE(YEAR(TODAY(),MONTH(TODAY())-6,DAY(TODAY()))
VAR Mnth12 = DATE(YEAR(TODAY(),MONTH(TODAY())-12,DAY(TODAY()))
RETURN
IF(([Last Sale date] <=Mnth3 &&[Last Sale date] >=Mnth6),"3to6 Months",(IF([Last Sale date] <=Mnth6 &&[Last Sale date] >=Mnth12,"6to12 Months",,(IF([Last Sale date] <=Mnth12,"More then 12 Months", "Recently"))))

 

 

Can You please suggest what should I do to get this result .

Thanks for you help in advance.

1 ACCEPTED SOLUTION

Hi @mb0307 ,

 

Please try this:

Column = 
VAR max_date =
    CALCULATE (
        MAX ( 'Table'[Inv date] ),
        ALLEXCEPT ( 'Table', 'Table'[Customer] )
    )
VAR diff =
    DATEDIFF ( max_date, TODAY (), MONTH )
RETURN
    SWITCH (
        TRUE (),
        diff < 3, "Recently",
        diff < 6, "3 to 6 Months",
        diff < 12, "6 to 12 Months",
        "More than 12 Months"
    )

v-xuding-msft_1-1597915785532.png

 

 

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

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@mb0307 , Try a new column with a date table in place join to date, else date from table

New column

 

Customer Not Bought =
VAR Mnth3 = CALCULATE(sumX(filter(Table,[Customer]=earlier([Customer])),Inv Amount),DATESINPERIOD('Date'[Date],today(),-3,MONTH))
VAR Mnth6 = CALCULATE(sumX(filter(Table,[Customer]=earlier([Customer])),Inv Amount),DATESINPERIOD('Date'[Date],today(),-6,MONTH))
VAR Mnth12 = CALCULATE(sumX(filter(Table,[Customer]=earlier([Customer])),Inv Amount),DATESINPERIOD('Date'[Date],today(),-12,MONTH))
RETURN
Switch ( True(),
not(isblank(Mnth3)) , "Recently",
not(isblank(Mnth6)) , "3 to 6 months",
not(isblank(Mnth3)) , "6 to 12 months",
"More then 12 Months"
)

 

 

Also, refer: new vs repeat customer
https://community.powerbi.com/t5/Desktop/Churn-Rate-lost-Customer/m-p/1173754#M529196
https://blog.enterprisedna.co/new-vs-existing-customers-advanced-analytics-w-dax/
https://www.sqlbi.com/articles/computing-new-customers-in-dax/

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi Amit,

 

Thanks for your reply. Earlier function is not working, it gives error Earlier/earliest refres to an earlier row context which doesn't exist)

Is there any other fuction which i can use.

 

I have made a VAR ear =[Customer]

VAR Mnth3 = CALCULATE(sumX(filter(Table,[Customer]=ear),Inv Amount),DATESINPERIOD('Date'[Date],today(),-3,MONTH))

Then it gives a same result as earlier i.e.  customer falls in every category.

 

 

 

Hi @mb0307 ,

 

Please try this:

Column = 
VAR max_date =
    CALCULATE (
        MAX ( 'Table'[Inv date] ),
        ALLEXCEPT ( 'Table', 'Table'[Customer] )
    )
VAR diff =
    DATEDIFF ( max_date, TODAY (), MONTH )
RETURN
    SWITCH (
        TRUE (),
        diff < 3, "Recently",
        diff < 6, "3 to 6 Months",
        diff < 12, "6 to 12 Months",
        "More than 12 Months"
    )

v-xuding-msft_1-1597915785532.png

 

 

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors