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
PedroAliança
Frequent Visitor

Filtro por VALOR ou QUANTIDADE

Bom dia,

 

Estou tentando criar um filtro em uma página para mudar entre valor e quantidade.

 

Porém os valores estão na mesma linha mas não na mesma coluna.

 

Para juntar os valores na mesma coluna eu dupliquei a base e na primeira acrescentei a coluna STATUS com o texto "VLR" e na segunda acrescentei a coluna STATUS com o texto "QTDE". Depois Mesclei as duas tabelas criando uma terceira base com os valores duplicados porem na coluna STATUS tenho como filtrar por "VLR" ou "QTDE". Por fim, fiz uma nova coluna chamada VALOR com o código: 

VALOR = IF(PEDIDODEVENDA_BI[STATUS]="VLR", PEDIDODEVENDA_BI[vl_total_2], PEDIDODEVENDA_BI[Qtd_Produto])

 

Isso funcionou muito bem, porém a formatação quando for filtrado por "VLR" tem que ser moeda e a formatação quando for filtrado por "QTDE" deve ser número inteiro. Mas eu só consigui definir uma formatação e não consegui fazer nenhuma fórmula que mude a formatação de acordo com o filtro.

 

É possivel mudar a formatação de acordo com o filtro? Tem alguma outra forma de fazer isso?

 

 

PedroAliana_0-1627649727592.png

Quando tiver filtrado por VLR os valores devem aparecer como MOEDA e quanto tiver filtrado por QTDE devem aparecer como NÚMERO INTEIRO

 

Desde já, obrigado!

1 ACCEPTED SOLUTION

Hi @PedroAliança 

 

Do you use the switch measure in the table visual, line chart visual and bar chart visual? I think it is because these charts expect numeric values to display whereas the measure returns Text type value when using Format function.

 

Using Calculation Groups may help solve this. I remembered I read a post earlier which used calculation groups to switch the format without changing data types, but I haven't used that before. You may first read Dynamic Formatting of Switch Measures - Excelerator BI and try this method. 

 

Sorry for not providing a solid solution. I will try my best to find another option. 

 

Regards,
Jing

View solution in original post

6 REPLIES 6
Syndicate_Admin
Administrator
Administrator

Hi @PedroAliança 

 

You can modify the Value column with below code. In this way, the Value column is of Text data type and populated with data in different formats. See FORMAT function (DAX).

VALUE =
IF (
    Append1[STATUS] = "VLR",
    FORMAT ( Append1[vl_total_2], "Currency" ),
    FORMAT ( Append1[Product_Qty], "General Number" )
)

080202.jpg

 

Another method is to add a parameter table in the model having values "VLR" & "QTDE" and put it in a slicer. And using a switch measure to display values dynamically according to the selected option in the slicer. In this way, you don't need to duplicate the base table and combine two tables. Then use Format function like above or calculation group in Tabular Editor to change the formatting dynamically. Here are some articles for your reference:

Change the Column or Measure Value in a Power BI Visual by Selection of the Slicer: Parameter Table ...

Dynamic Formatting of Switch Measures - Excelerator BI

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

Bom dia, Jing!

Obrigado pela resposta e ótimas indicações.

 

Mudei o método, estou utilizando somente uma base e agora estou fazendo por SWITCH.

 

 

Medidas = 
SWITCH(
    'Selecao Medidas'[Medida Selecionada],
    1,[Valor],
    2,[Quantidade]
)

 

Quando utilizo esse código, não está puxando a formatação, mas a tabela funciona perfeitamento com os filtros. Segue foto:

PedroAliana_0-1627912054592.png

 

 

 

 

Medidas = 
SWITCH(
    'Selecao Medidas'[Medida Selecionada],
    1, FORMAT([Valor], "currency"),
    2, FORMAT([Quantidade], "general number")
)

 

Quando eu utilizo este código com o FORMAT, funciona a formatação porém puxa valores em branco, e não funcionam os gráficos. Segue foto:

PedroAliana_1-1627912257319.png

Já tentei filtrar: "Não está em branco", "Não está vazio" "Maior que 0". Nada funcionou. Apesar do filtro de data (lado esquedo superior) funcionar, aparecem os campos em branco. Valor total está certo.


 

 

Desde já, muito obrigado.

Hi @PedroAliança 

 

Do you use the switch measure in the table visual, line chart visual and bar chart visual? I think it is because these charts expect numeric values to display whereas the measure returns Text type value when using Format function.

 

Using Calculation Groups may help solve this. I remembered I read a post earlier which used calculation groups to switch the format without changing data types, but I haven't used that before. You may first read Dynamic Formatting of Switch Measures - Excelerator BI and try this method. 

 

Sorry for not providing a solid solution. I will try my best to find another option. 

 

Regards,
Jing

Hi Jing!

 

Eu fiz esse metódo pelo Tabular Editor e funcionou perfeitamente!

 

Muito obrigado pela ajuda! 

That's great! Cheers!

v-jingzhang
Community Support
Community Support

Hi @PedroAliança 

 

You can modify the Value column with below code. In this way, the Value column is of Text data type and populated with data in different formats. See FORMAT function (DAX).

VALUE =
IF (
    Append1[STATUS] = "VLR",
    FORMAT ( Append1[vl_total_2], "Currency" ),
    FORMAT ( Append1[Product_Qty], "General Number" )
)

080202.jpg

 

Another method is to add a parameter table in the model having values "VLR" & "QTDE" and put it in a slicer. And using a switch measure to display values dynamically according to the selected option in the slicer. In this way, you don't need to duplicate the base table and combine two tables. Then use Format function like above or calculation group in Tabular Editor to change the formatting dynamically. Here are some articles for your reference:

Change the Column or Measure Value in a Power BI Visual by Selection of the Slicer: Parameter Table ...

Dynamic Formatting of Switch Measures - Excelerator BI

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

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