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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Nobeltex_PBI
New Member

Clientes Ativos por Grupo de Clientes

Preciso de uma medida que conte todos os clientes de um grupo se um CNPJ desse grupo atender a regra de cliente ativo. Montei a medida abaixo mas não deu certo.

Estou adicionando também o modelo de dados e a tabela que tenho como resultado hoje. Percebam que apenas alguns cnpj's do grupo ficam com o 1 e preciso que todos fiquem.

 

Clientes Ativos =
VAR vDiasAtividade = SELECTEDVALUE('Atividade Comercial'[Dias])
VAR v2Compras =
FILTER(
ALL(fatVenda[id_cliente]),
CALCULATE(
[Qtde Pedidos Comercial],
FILTER(
ALL(dimCalendario),
dimCalendario[Data] >= TODAY() - vDiasAtividade
),
USERELATIONSHIP(fatVenda[id_vendedor_atual], dimVendedor[id_vendedor])
)>=2
)
VAR v2ComprasForaAtividade =
FILTER(
ALL(fatVenda[id_cliente]),
CALCULATE(
[Qtde Pedidos Comercial],
FILTER(
ALL(dimCalendario),
dimCalendario[Data] >= TODAY() - vDiasAtividade - 180 &&
dimCalendario[Data] < TODAY() - vDiasAtividade
),
USERELATIONSHIP(fatVenda[id_vendedor_atual], dimVendedor[id_vendedor])
)>=2
)
VAR vClientesNovos =
INTERSECT(v2Compras, v2ComprasForaAtividade)
RETURN
COUNTROWS(vClientesNovos)Imagem_01.JPGImagem_02.JPG
1 ACCEPTED SOLUTION

Hi @Nobeltex_PBI ,

 

Please try the following formula:

 

Measure = 
var tab = 
    CALCULATETABLE ( 
        VALUES ( dimCliente[Group] ), 
        FILTER ( 
            ALL ( dimCliente ),
            dimCliente[Group] = MAX ( dimCliente[Group] )
                && [Clientes Ativos] > 0
        )
    )
return 
    CALCULATE (
        COUNT ( dimCliente[id_cliente] ),
        FILTER ( all ( dimCliente ), dimCliente[Group] in tab )
    )

vkkfmsft_0-1639032833625.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

@Nobeltex_PBI , what is the logic for the active customers? please share that

 

refer example

Customer Retention Part 5: LTD Vs Period Retention
https://community.powerbi.com/t5/Community-Blog/Customer-Retention-Part-5-LTD-and-PeriodYoY-Retentio...

 

 

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

The logic for finding active customers is correct. What I need is that if a customer in the group meets the logic, all the others, even not meeting it, must count as assets. Did you understand?

Hi @Nobeltex_PBI ,

 

Please try the following formula:

 

Measure = 
var tab = 
    CALCULATETABLE ( 
        VALUES ( dimCliente[Group] ), 
        FILTER ( 
            ALL ( dimCliente ),
            dimCliente[Group] = MAX ( dimCliente[Group] )
                && [Clientes Ativos] > 0
        )
    )
return 
    CALCULATE (
        COUNT ( dimCliente[id_cliente] ),
        FILTER ( all ( dimCliente ), dimCliente[Group] in tab )
    )

vkkfmsft_0-1639032833625.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.