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
Anonymous
Not applicable

Calculate column percentage from calculated column

I need to calculate the percentage of calculated column B, based on column A +B. I have two calculated columns, each one for a customer segment.

A - Column Retention = Customers that had their first purchase before 2021

 

Formula:

 

Vendas clientes Retenção < 2021 =
VAR m = 'Base Clientes e Pedidos'[Data_primeiro_pedido]
RETURN
CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER('Base Clientes e Pedidos', m <= DATE(2021,01,01)))

 

 

 


B - Column New Clientes = Customers that had their first purchase after 2021

Formula:
Vendas clientes novos >2021 =
VAR m = 'Base Clientes e Pedidos'[Data_primeiro_pedido]
RETURN
CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER('Base Clientes e Pedidos', m >= DATE(2021,01,01)))

 



I'm having a hard time to calculate the percentage % of new clients based on the calculated columns. 

What i need: B/(A+B)

I've tried:

 

% Venda para Novos =
VAR m = 'Base Clientes e Pedidos'[Data_primeiro_pedido]
RETURN
DIVIDE(CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER('Base Clientes e Pedidos', m >= DATE(2021,01,01)
)
), DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob])
)

 

 

 

But it doesn't work as expected, returning the value of column B instead of B/(A+B)

1 ACCEPTED SOLUTION
andhiii079845
Solution Sage
Solution Sage

Do you really create two calculated columns or measures? 

You can try this:

 

MEASURE =
VAR m = 'Base Clientes e Pedidos'[Data_primeiro_pedido]
VAR _2021 =
CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER('Base Clientes e Pedidos', m <= DATE(2021,01,01)))

VAR _2022 =

CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER('Base Clientes e Pedidos', m > DATE(2021,01,01)))

RETURN 

_2021/(_2021+_2022)

 

If it not work. Please post your underlaying data structure and where do you want to use this measure.

AND be aware of <= and >=. In This case you will count rows with 2021-01-01 twice!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Anonymous
Not applicable

I've tried both solutions, but it doesn't allow me to filter data to each Sales Person 

As follow:

matheusppedroso_0-1679339694800.png

 

Change ...

FILTER(ALL('Base Clientes e Pedidos'), 'Base Clientes e Pedidos'[Data_primeiro_pedido]

To...

FILTER(ALL('Base Clientes e Pedidos'[Data_primeiro_pedido]), 'Base Clientes e Pedidos'[Data_primeiro_pedido]
BrianConnelly
Resolver III
Resolver III

Try the following...

% Venda para Novos =
VAR B = CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER(ALL('Base Clientes e Pedidos'), 'Base Clientes e Pedidos'[Data_primeiro_pedido] >= DATE(2021,01,01)))

VAR A = CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER(ALL('Base Clientes e Pedidos'), 'Base Clientes e Pedidos'[Data_primeiro_pedido] < DATE(2021,01,01)))

RETURN DIVIDE(B,A+B,0)
andhiii079845
Solution Sage
Solution Sage

Do you really create two calculated columns or measures? 

You can try this:

 

MEASURE =
VAR m = 'Base Clientes e Pedidos'[Data_primeiro_pedido]
VAR _2021 =
CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER('Base Clientes e Pedidos', m <= DATE(2021,01,01)))

VAR _2022 =

CALCULATE(DISTINCTCOUNT('Base Clientes e Pedidos'[id_pedido_promob]),
FILTER('Base Clientes e Pedidos', m > DATE(2021,01,01)))

RETURN 

_2021/(_2021+_2022)

 

If it not work. Please post your underlaying data structure and where do you want to use this measure.

AND be aware of <= and >=. In This case you will count rows with 2021-01-01 twice!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hello, i've created calculated columns, thats why i could calculate each row. Changin it to measure and it worked!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.

June 2025 community update carousel

Fabric Community Update - June 2025

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