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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
0Experience
Frequent Visitor

Calculate Percentage based on Filter

Hello,

 

I have several locations categorized into different zones. For instance, Loc_1 and Loc_2 belong to Zone N, and Zone C respectively, with their summation being 9.

0Experience_0-1707754141806.png

I can count this using

Sum_of_All_Zone_Loc_Pop_filter = 
CALCULATE(
    SUM(Table1[Loc_Pop]), 
    Table1[Category] = "Cat_total"
)

 

Now, what I aim to accomplish is determining the percentage of these two selected locations (Loc_1, Loc_2) relative to all locations within their respective zones. For instance, if the count of these selected locations within Zone N and Zone C is 9, and the total count of all locations within these zones is 23.

0Experience_1-1707754200727.png

 

I am trying to do this the following formula (but not giving the actual result, as I don't know how I can filter the locations based on the zones)

 

Percentage_of_Zones = FORMAT(
                            DIVIDE(
                                CALCULATE(SUM(Table1[Loc_Pop]),
                                Table1[Category] = "Cat_total"),

                                CALCULATE(SUM(Table1[Loc_Pop]),
                                ALL(Table1[Location]),
                                Table1[Category] = "Cat_total")
                            ),
                            "0.00%"
                            )

 

Any insights or suggestions would be greatly appreciated. Thank you for your time and assistance.


Data and .pbix (Google Drive). Appreciate if you share the answer on the post or Google drive.OneDrive.

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

Try adding VALUES ( Table1[Zone] ) to preserve the Zone context associated with Loc_1 and Loc_2. Otherwise, you'll pick up zones associated with other locations (zones S and E) in your denominator.

Percentage_of_Zones =
FORMAT (
    DIVIDE (
        CALCULATE (
            SUM ( Table1[Loc_Pop] ),
            Table1[Category] = "Cat_total"
        ),
        CALCULATE (
            SUM ( Table1[Loc_Pop] ),
            ALL ( Table1[Location] ),
            VALUES ( Table1[Zone] ),
            Table1[Category] = "Cat_total"
        )
    ),
    "0.00%"
)

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

Try adding VALUES ( Table1[Zone] ) to preserve the Zone context associated with Loc_1 and Loc_2. Otherwise, you'll pick up zones associated with other locations (zones S and E) in your denominator.

Percentage_of_Zones =
FORMAT (
    DIVIDE (
        CALCULATE (
            SUM ( Table1[Loc_Pop] ),
            Table1[Category] = "Cat_total"
        ),
        CALCULATE (
            SUM ( Table1[Loc_Pop] ),
            ALL ( Table1[Location] ),
            VALUES ( Table1[Zone] ),
            Table1[Category] = "Cat_total"
        )
    ),
    "0.00%"
)

@AlexisOlson thanks, it is working!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors