Forum Discussion
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, Anonymous ?
Muito obrigado...
- Anonymous5 years ago
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 _flag2. 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.
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.
2 Replies
- AnonymousNot applicable
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 _flag2. 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.
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.
- LuanRamosFrequent Visitor
Anonymous, tks.
You've help me a lot!