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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors