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
George_H
Frequent Visitor

Filtering out multiple values for division calculation.

Hello,

I would like to do the caluation (Cat) / (Cat + Dog) from a column. But I have two other metrics I don't want to include in the calauation (Mouse & Rabbit), and would would like to filter out.

The [NoPet] measure is a count of all the pets. 

Here is my code but it is not working. 

Pets C/D = DIVIDE(CALCULATE([NoPet],'Animals'[Pets]IN {"Cat"}),CALCULATE([NoPet],FILTER('Animals','Animals'[Pets] <> "Mouse" || 'Animals'[Pets] <> "Rabbit")))
 
Could you please suggest workable and efficent way of doing this caluation? 
 
Thanks!
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure what visualization you want to present the result, but please try something like, 

 

Pets C/D =
DIVIDE (
    CALCULATE ( [NoPet], 'Animals'[Pets] IN { "Cat" } ),
    CALCULATE ( [NoPet], 'Animals'[Pets] IN { "Cat", "Dog" } )
)

 

Or,

 

Pets C/D =
DIVIDE (
    CALCULATE ( [NoPet], 'Animals'[Pets] IN { "Cat" } ),
    CALCULATE (
        [NoPet],
        FILTER ( 'Animals', 'Animals'[Pets] <> "Mouse" && 'Animals'[Pets] <> "Rabbit" )
    )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
PabloDeheza
Solution Sage
Solution Sage

Hi there!

Can you provice de DAX code of [NoPet].

In the meantime you can try:

Pets C/D =
DIVIDE(
    CALCULATE( [NoPet], 'Animals'[Pets] = "Cat" ),
    CALCULATE( [NoPet], 'Animals'[Pets] IN { "Cat", "Dog" } )
)

Let me know if that helps!

Jihwan_Kim
Super User
Super User

Hi,

I am not sure what visualization you want to present the result, but please try something like, 

 

Pets C/D =
DIVIDE (
    CALCULATE ( [NoPet], 'Animals'[Pets] IN { "Cat" } ),
    CALCULATE ( [NoPet], 'Animals'[Pets] IN { "Cat", "Dog" } )
)

 

Or,

 

Pets C/D =
DIVIDE (
    CALCULATE ( [NoPet], 'Animals'[Pets] IN { "Cat" } ),
    CALCULATE (
        [NoPet],
        FILTER ( 'Animals', 'Animals'[Pets] <> "Mouse" && 'Animals'[Pets] <> "Rabbit" )
    )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thank you! The top one works perfectly.  I'm using it in a line chart to compare the percentage of cats to dogs over time. 

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