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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
camilocorralesg
Advocate I
Advocate I

Filter a Measure that uses CALCULATE with a slicer

I have a client data base, i first calculate the total amount of people that are in my dataset.

 

Numero de clientes = COUNTROWS('Clientes')

 

 

after that, i proceed to calculate the amount of men and women that are in my dataset using CALCULATE

 

Hombres = var hombres = CALCULATE( [Numero de clientes], 'Clientes'[Sexo] = "Masculino")) return if(isblank(hombres), 0, hombres)
Mujeres = var mujeres = CALCULATE([Numero de clientes], 'Clientes'[Sexo] = "Femenino")) return if(isblank(mujeres), 0, mujeres)

 

 

Next i want to know the %

 

% Hombres = [Hombres] / [Numero de clientes]
% Mujeres = [Mujeres] / [Numero de clientes]

 

 

This is the result: camilocorralesg_0-1648925790268.png

Then i try to filter using a slicer, i should get 0 in "Mujeres" when i select for example to show only info related to "hombres", instead i'm getting this:camilocorralesg_1-1648927683209.png

How can i resolve this? If i selected "Masculino" i should get Hombres: 21 100% hombres and 0 Mujeres 0% Mujeres.

Thanks for the help!

2 ACCEPTED SOLUTIONS
PaulDBrown
Community Champion
Community Champion

Try these for [Hombres] and [Mujeres]:

Hombres = 
var hombres = CALCULATE( [Numero de clientes],FILTER('Clientes, 'Clientes'[Sexo] = "Masculino")) 
return if(isblank(hombres), 0, hombres)
Mujeres = 
var mujeres = CALCULATE([Numero de clientes],FILTER('Clientes', 'Clientes'[Sexo] = "Femenino")) 
return if(isblank(mujeres), 0, mujeres)




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

v-zhangti
Community Support
Community Support

Hi, @camilocorralesg 

 

You can try the following methods.

Numero de clientes = COUNTROWS('Clientes')
Hombres = 
IF (
    SELECTEDVALUE ( Clientes[Sexo] ) = "Masculino",
    CALCULATE ( [Numero de clientes], 'Clientes'[Sexo] = "Masculino" ),
    IF (
        SELECTEDVALUE ( Clientes[Sexo] ) = BLANK (),
        CALCULATE ( [Numero de clientes], 'Clientes'[Sexo] = "Masculino" ),
        0
    )
)
Mujeres = 
IF (
    SELECTEDVALUE ( Clientes[Sexo] ) = "Femenino",
    CALCULATE ( [Numero de clientes], 'Clientes'[Sexo] = "Femenino" ),
    IF (
        SELECTEDVALUE ( Clientes[Sexo] ) = BLANK (),
        CALCULATE ( [Numero de clientes], 'Clientes'[Sexo] = "Femenino" ),
        0
    )
)

The rest of the equations remain unchanged.

vzhangti_0-1649139363396.png

vzhangti_1-1649139385921.pngvzhangti_2-1649139398667.png

Does this meet your expected results?

 

Best Regards,

Community Support Team _Charlotte

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
v-zhangti
Community Support
Community Support

Hi, @camilocorralesg 

 

You can try the following methods.

Numero de clientes = COUNTROWS('Clientes')
Hombres = 
IF (
    SELECTEDVALUE ( Clientes[Sexo] ) = "Masculino",
    CALCULATE ( [Numero de clientes], 'Clientes'[Sexo] = "Masculino" ),
    IF (
        SELECTEDVALUE ( Clientes[Sexo] ) = BLANK (),
        CALCULATE ( [Numero de clientes], 'Clientes'[Sexo] = "Masculino" ),
        0
    )
)
Mujeres = 
IF (
    SELECTEDVALUE ( Clientes[Sexo] ) = "Femenino",
    CALCULATE ( [Numero de clientes], 'Clientes'[Sexo] = "Femenino" ),
    IF (
        SELECTEDVALUE ( Clientes[Sexo] ) = BLANK (),
        CALCULATE ( [Numero de clientes], 'Clientes'[Sexo] = "Femenino" ),
        0
    )
)

The rest of the equations remain unchanged.

vzhangti_0-1649139363396.png

vzhangti_1-1649139385921.pngvzhangti_2-1649139398667.png

Does this meet your expected results?

 

Best Regards,

Community Support Team _Charlotte

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

CNENFRNL
Community Champion
Community Champion

Hombres =
CALCULATE(
    [Numero de clientes],
    KEEPFILTERS( 'Clientes'[Sexo] = "Masculino" )
) + 0
Mujeres =
CALCULATE(
    [Numero de clientes],
    KEEPFILTERS( 'Clientes'[Sexo] = "Femenino" )
) + 0

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

PaulDBrown
Community Champion
Community Champion

Try these for [Hombres] and [Mujeres]:

Hombres = 
var hombres = CALCULATE( [Numero de clientes],FILTER('Clientes, 'Clientes'[Sexo] = "Masculino")) 
return if(isblank(hombres), 0, hombres)
Mujeres = 
var mujeres = CALCULATE([Numero de clientes],FILTER('Clientes', 'Clientes'[Sexo] = "Femenino")) 
return if(isblank(mujeres), 0, mujeres)




Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.