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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
cghanta
Helper I
Helper I

Calculate percentage from 2 columns

I have a table UPS with 2 columns
location Maint_1 Maint_2
City1Yesn/a
City2YesYes
City3No 
City4YesNo

I need to calculate percentage (Measure in Power BI) of Cities where no maintenance is done from the 2 Maint_1 & Maint_2 columns, ignoring the "n/a" and null/no values.

In the above table, "%Cities with no maint" = 2/6 *100 = 33.33

numerator = 2 (No + No)

divisor = 6 (Yes + Yes + No + Yes + Yes + No)
if all values are Yes or n/a or blank, the answer should be 0.00
Thank you in advance.

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @cghanta ,

 

You can calculate the percentage of cities where no maintenance is done from both Maint_1 and Maint_2 columns using a DAX measure in Power BI. The idea is to combine the two columns into a single virtual table, filter out any values that are either "n/a" or blank, and then count how many of the remaining values are "No". This count becomes your numerator. The denominator is the total number of valid values ("Yes" or "No"). Finally, you divide the two and multiply by 100 to get the percentage. Here's how you can write the measure:

%Cities with no maint = 
VAR AllValues =
    UNION (
        SELECTCOLUMNS(UPS, "Maint", UPS[Maint_1]),
        SELECTCOLUMNS(UPS, "Maint", UPS[Maint_2])
    )
VAR Filtered =
    FILTER (
        AllValues,
        NOT (ISBLANK([Maint])) && [Maint] <> "n/a"
    )
VAR NoCount =
    COUNTROWS (
        FILTER (Filtered, [Maint] = "No")
    )
VAR TotalValid =
    COUNTROWS (
        FILTER (Filtered, [Maint] IN {"Yes", "No"})
    )
RETURN
    IF (
        TotalValid = 0,
        0,
        DIVIDE(NoCount, TotalValid) * 100
    )

This will return 33.33 in your example, as there are 2 "No" values out of 6 valid values ("Yes" or "No"). If all entries are either "Yes", "n/a", or blank, the measure will correctly return 0.00.

 

Best regards,

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @cghanta ,

 

You can calculate the percentage of cities where no maintenance is done from both Maint_1 and Maint_2 columns using a DAX measure in Power BI. The idea is to combine the two columns into a single virtual table, filter out any values that are either "n/a" or blank, and then count how many of the remaining values are "No". This count becomes your numerator. The denominator is the total number of valid values ("Yes" or "No"). Finally, you divide the two and multiply by 100 to get the percentage. Here's how you can write the measure:

%Cities with no maint = 
VAR AllValues =
    UNION (
        SELECTCOLUMNS(UPS, "Maint", UPS[Maint_1]),
        SELECTCOLUMNS(UPS, "Maint", UPS[Maint_2])
    )
VAR Filtered =
    FILTER (
        AllValues,
        NOT (ISBLANK([Maint])) && [Maint] <> "n/a"
    )
VAR NoCount =
    COUNTROWS (
        FILTER (Filtered, [Maint] = "No")
    )
VAR TotalValid =
    COUNTROWS (
        FILTER (Filtered, [Maint] IN {"Yes", "No"})
    )
RETURN
    IF (
        TotalValid = 0,
        0,
        DIVIDE(NoCount, TotalValid) * 100
    )

This will return 33.33 in your example, as there are 2 "No" values out of 6 valid values ("Yes" or "No"). If all entries are either "Yes", "n/a", or blank, the measure will correctly return 0.00.

 

Best regards,

Thank you @DataNinja777

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

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.

Top Solution Authors