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
LuanRamos
Frequent Visitor

Calcular clientes ativos

Olá, pessoal!

 

Tenho uma base com os seguintes campos: Data de Venda; Cod_Cliente; Valor de Venda

 

Como posso calcular quantos clientes realizaram 1 compra, ou mais, nos últimos três meses?

 

Ex.: se eu colocar no filtro o mês de julho, quantos clientes fizeram 1 compra, ou mais, entre os meses de Maio, Junho ou Julho?

 

Pode me ajudar, @v-yangliu-msft ?

 

Muito obrigado...

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @LuanRamos,

 

Here are the steps you can follow:

1. Create a calculated column.

 

purchase=
var _3monthbefore=
CALCULATE(
    COUNT('Table'[Amount]),
    FILTER('Table',
[Cod_Cliente]=EARLIER([Cod_Cliente])
&&
MONTH([Date])=MONTH(EARLIER([Date]))-3))

var _2monthbefore=
CALCULATE(
   COUNT('Table'[Amount]),
    FILTER('Table',
[Cod_Cliente]=EARLIER([Cod_Cliente])
&&
MONTH([Date])=MONTH(EARLIER([Date]))-2))

var _1monthbefore=
CALCULATE(
    COUNT('Table'[Amount]),
    FILTER('Table',
[Cod_Cliente]=EARLIER([Cod_Cliente])
&&
MONTH([Date])=MONTH(EARLIER([Date]))-1))

var _flag=
SWITCH(
    TRUE(),
    _1monthbefore =1||_2monthbefore=1||_3monthbefore=1, "One time purchase",
     _1monthbefore >1||_2monthbefore>1||_3monthbefore>1,"Multiple purchases",
    "No purchase")

return _flag

2. Create measure

PURCHASE TIME =
var _month=SELECTEDVALUE('Month'[Month])
RETURN
IF(
    MONTH(MAX('Table'[Date]))>=_month-2&&MONTH(MAX('Table'[Date]))<=_month,
    1,0)

3. Result.

v-yangliu-msft_0-1605234202962.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @LuanRamos,

 

Here are the steps you can follow:

1. Create a calculated column.

 

purchase=
var _3monthbefore=
CALCULATE(
    COUNT('Table'[Amount]),
    FILTER('Table',
[Cod_Cliente]=EARLIER([Cod_Cliente])
&&
MONTH([Date])=MONTH(EARLIER([Date]))-3))

var _2monthbefore=
CALCULATE(
   COUNT('Table'[Amount]),
    FILTER('Table',
[Cod_Cliente]=EARLIER([Cod_Cliente])
&&
MONTH([Date])=MONTH(EARLIER([Date]))-2))

var _1monthbefore=
CALCULATE(
    COUNT('Table'[Amount]),
    FILTER('Table',
[Cod_Cliente]=EARLIER([Cod_Cliente])
&&
MONTH([Date])=MONTH(EARLIER([Date]))-1))

var _flag=
SWITCH(
    TRUE(),
    _1monthbefore =1||_2monthbefore=1||_3monthbefore=1, "One time purchase",
     _1monthbefore >1||_2monthbefore>1||_3monthbefore>1,"Multiple purchases",
    "No purchase")

return _flag

2. Create measure

PURCHASE TIME =
var _month=SELECTEDVALUE('Month'[Month])
RETURN
IF(
    MONTH(MAX('Table'[Date]))>=_month-2&&MONTH(MAX('Table'[Date]))<=_month,
    1,0)

3. Result.

v-yangliu-msft_0-1605234202962.png

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

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

@v-yangliu-msft, tks.

 

You've help me a lot!

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.

Top Solution Authors