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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
deizesilveira
New Member

Transformar medida dax em segmentação de dados

Tenho uma medida dax que apresenta o Status de Cliente "Sem Crescimento", "Com Crescimento", "Sem Histórico" e "Sem Compra". Atualmente essa medida está disposta em uma tabela com outras informações do cliente como nome, Venda Bruta, Venda Bruta Ano Anterior, Variação AA, etc. Preciso de uma solução para transformar essa medida dax em uma segmentação de dados, onde o usuário possa selecionar no filtro uma das 4 opções e visualizar na tabela somente o Status Selecionado.
Já tentei de algumas formas e nenhuma trouxe um resultado coerente e completo.

Abaixo a fórmula dax Status Cliente:

Status Cliente =
VAR VendasAtual = [Venda Bruta]
VAR VendasAnterior = [Venda Bruta AA]

RETURN IF(ISBLANK(VendasAtual) = FALSE() && ISBLANK(VendasAnterior) = FALSE() && VendasAtual > VendasAnterior,
    "COM CRESCIMENTO", IF(VendasAtual = 0 && VendasAnterior > 0, "SEM COMPRA", IF(VendasAtual > 0 && VendasAnterior > 0 && VendasAtual < VendasAnterior"SEM CRESCIMENTO"IF(VendasAnterior = 0 && VendasAtual > 0"SEM HISTÓRICO"BLANK()))))

Agradeço desde já pelo apoio.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @deizesilveira ,

 

first we need create a enter table like:
'DimStatusCliente'

vcgaomsft_0-1719882271244.png

the relationship:

vcgaomsft_1-1719882335655.png

And then create a new measure:

Filter Status Cliente = 
VAR __slicer = ALLSELECTED('DimStatusCliente'[Status Cliente])
VAR __result = IF( [Status Cliente] IN __slicer, 1 )
RETURN
__result

 And then use this measure as the table's filter:

vcgaomsft_2-1719882381607.png

Output:

vcgaomsft_3-1719882412403.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @deizesilveira ,

 

first we need create a enter table like:
'DimStatusCliente'

vcgaomsft_0-1719882271244.png

the relationship:

vcgaomsft_1-1719882335655.png

And then create a new measure:

Filter Status Cliente = 
VAR __slicer = ALLSELECTED('DimStatusCliente'[Status Cliente])
VAR __result = IF( [Status Cliente] IN __slicer, 1 )
RETURN
__result

 And then use this measure as the table's filter:

vcgaomsft_2-1719882381607.png

Output:

vcgaomsft_3-1719882412403.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Muito obrigada pela sugestão!

Mas um ponto importante é que "Status Cliente" não existe em uma estrutura fixa de tabela, é uma medida dax. Quando digo: "Atualmente essa medida está disposta em uma tabela com outras informações do cliente como nome, Venda Bruta, Venda Bruta Ano Anterior, Variação AA, etc." quero dizer que adicionei um visual de tabela e dentro dele coloquei a coluna nome do cliente e as medidas dax criadas, como "Status Cliente", "Venda Bruta", "Venda Bruta Ano Anterior", etc.

Hoje esse Status Cliente é definido através da venda do cliente, vou adicionar as medidas que definem esses Status (Com Crescimento, Sem Crescimento, Sem Histórico e Sem Compra) abaixo (
[Venda Bruta] e [Venda Bruta AA]):

Venda Bruta =
CALCULATE(
    SUMX(
        FILTER(
            'tabela_venda',
            'tabela_venda'[FG_ITEM_COM_RECUSA_COM] = "Não"),
        'tabela_venda'[VL_LIQUIDO_ITEM]
    )
) +
CALCULATE(
    SUMX(
        FILTER(
            'tabela_venda',
            'tabela_venda'[FG_ITEM_COM_RECUSA_COM] = "Sim"),
        'tabela_venda'[VL_CAN_TOT]
    )
)

 

Venda Bruta AA =
VAR ColecaoAnterior = [Coleção Anterior]

RETURN
    CALCULATE([Venda Bruta],
        ALL(dim_chave[CHAVE_COLECAO_COMERCIAL]),
        dim_chave[CHAVE_COLECAO_COMERCIAL] = ColecaoAnterior
    )
Anonymous
Not applicable

Hi @deizesilveira ,

 

I understand that [Status Cliente] is a measure. 

But since Slicer only accepts columns as values, here I've added all the output values from [Status Cliente] to a table.

Finally a metric is created to get the values in the slicer and pass them to the visual filter.

You may refer to the example file I uploaded earlier.

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.