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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
vinaydavid
Helper III
Helper III

Measure to calculate Percentages - Usage - ALLEXCEPT()

Hi Experts,

 

I have been trying to get the percentage values right for my calculations.

Need a bit of code help in getting the right percentages.

Here is the scenario.

 

NameProjectLeavesNumber of daysHoursPercentage (Expected)
AAARed 2397.920.71
AAABlue 2341.830.30
BBB 15.22315.200.00
BBBRed 23136.801.11
CCCRed 2389.000.64
CCCGreen 234.000.03
DDD 242324.000.00

 

 

Percentage = 
VAR __DAYS =
    CALCULATE ( SUM ( Testing[Number of days] ) )
VAR __LEAVES =
    CALCULATE ( SUM ( Testing[Leaves] ) )
RETURN
    DIVIDE (
        CALCULATE (
            SUM ( Testing[Hours] ),
            ALLEXCEPT ( Testing, Testing[Name], Testing[Project] )
        ),
        ( __DAYS * 6 ) - __LEAVES,
        0
    )

 

 

The above formula doesn't seem to be deducting the leaves from the denominator.

Eg: For User BBB, I want the calculation to be  (136.8)/ (23 * 6) - (15.2) = 1.11

      But the above formula doesn't help, resulting in 136.8 / (23 * 6) => 0.99 (thats incorrect)

 

Note: Leave hours doesn't have project details.

 

Here is a sample PBIX.

https://1drv.ms/u/s!Ao2V7OnnFNS_hR5Ofj6eCl7rn2uL?e=c3nGzt 

1 ACCEPTED SOLUTION

@vinaydavid 

 

You may simply use ALLSELECTED.

VAR __LEAVES =
    CALCULATE ( SUM ( Testing[Leaves] ), ALLSELECTED ( Testing[Project] ) )

 

Community Support Team _ Sam Zha
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

5 REPLIES 5
danextian
Super User
Super User

Hi @vinaydavid 

 

You have one more lines for each project name. The second of BBB doesn't have leaves so it is not being included in the calculation. You can try this formula: 

Percentage_ =
VAR __DAYS =
    SUM ( Testing[Number of days] ) * 6
VAR __LEAVES =
    CALCULATE ( SUM ( Testing[Leaves] ), ALLEXCEPT ( Testing, Testing[Name] ) )
VAR __HOURS =
    SUM ( Testing[Hours] )
RETURN
    IF (
        SELECTEDVALUE ( Testing[Project] ) = BLANK (),
        0,
        DIVIDE ( __HOURS, __DAYS - __LEAVES )
    )




Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks @danextian  for the response.

 

The formula is working perfectly fine. But its picking all the leave values for the 'Name'. I want to restrict it by a date filter. (Sorry not informed earlier)

 

Apologies as its a test data, I missed to include the date filter.

The report has a date selection (From & to dates). 

Something like this. (not in the sample pbix)

 

 

FILTER ( Testing,
         Testing[LogDate] <= __END_QUERY
         && Testing[LogDate] >= __START_QUERY
         )

 

 

How can I incorporate to get the '__LEAVES' variable values as 15.20 on a Name level by using the above filter.

 

I tried to put the above filter, but then it give me '15.20' (empty project) '0' (with project) for BBB.

Thanks!

 

Change this line from

VAR __LEAVES =
    CALCULATE ( SUM ( Testing[Leaves] ), ALLEXCEPT ( Testing, Testing[Name] ) )

to

VAR __LEAVES =
    CALCULATE ( SUM ( Testing[Leaves] ), ALLEXCEPT ( Testing, Testing[Name], Testing[Date] ) )

This should keep the total sum of leaves by each unique name but still allow the breakdown by date.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks @danextian,

I understand, where you are coming from.

But I guess, calculate function works in a way to pick all the dates for each name (in this case BBB), and it doesn't have the impact of the Slicer.(Correct me if I am wrong).

So when I used your code, its displaying more hours (ie., all the hours from the database for BBB user).

 

Also tested, Filter() to restrict the data in calculate function, but then it work on row context to display the correct value only for 'Blank' Project. And corresponding row with a project for name BBB has hours as 'Blank'.

 

 

@vinaydavid 

 

You may simply use ALLSELECTED.

VAR __LEAVES =
    CALCULATE ( SUM ( Testing[Leaves] ), ALLSELECTED ( Testing[Project] ) )

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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
Top Kudoed Authors