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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Fusilier2
Helper V
Helper V

Calculate % of total with filtering

I'm stuck with DAX. Hopefully this is simple to achieve.

I have three department levels in a hierarchy:

Director dept

Service

Cost Centre

I think I need two DAX  measures:

1. I want to calculate Hours Absent as a % of total Hours absent for each level when filtered

So, if total sickness days for the company as a whole was 100 and I select Director Dept 'A' where total Hours absent was 50, the measure would return 50% and so on for each level in the hierarchy as drilled down.

 

2.  I also want a measure that will calculate the % at each level as a proportion of the total at that level.

For example Service dept B/Director dept A where Service dept B is part of Director dept A.

I've tried this measure:

Hours Absent as % of Total = DIVIDE(CALCULATE([Sum of Hours Absent],ALLSELECTED('Monthly Sickness Data'[Hours Absent ]))
But this doesn't work. Can anybody help or point me in the right direction please?

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @Fusilier2 

Based on your description, I have created some measures to achieve the effect you are looking for. Following picture shows the effect of the display.

vyaningymsft_0-1712816166901.png

Measure:

Absent days all % = 
VAR _director =
    CALCULATE ( SUM ( 'Director dept'[Absent Days] ) )
VAR _service =
    CALCULATE ( SUM ( Service[Absent] ) )
VAR _costCenter =
    CALCULATE ( SUM ( 'Cost Center'[Absent] ) )
VAR _dept =
    SELECTEDVALUE ( 'Company dept A'[Dept A] )
VAR _allAbesent = _costCenter + _director + _service
RETURN
    SWITCH (
        _dept,
        "Cost Center", DIVIDE ( _costCenter, _allAbesent ),
        "Director dept", DIVIDE ( _director, _allAbesent ),
        "Service", DIVIDE ( _service, _allAbesent ),
        "Pls Select Dept"
    )
Absent days level % = 
VAR _director =
    CALCULATE ( SUM ( 'Director dept'[Absent Days] ) )
VAR _service =
    CALCULATE ( SUM ( Service[Absent] ) )
VAR _costCenter =
    CALCULATE ( SUM ( 'Cost Center'[Absent] ) )
VAR _deptA =
    SELECTEDVALUE ( 'Company dept A'[Dept A] )
VAR _deptB =
    SELECTEDVALUE ( 'Company dept B'[Dept B] )
VAR _A =
    SWITCH (
        _deptA,
        "Cost Center", _costCenter,
        "Director dept", _director,
        "Service", _service
    )
VAR _B =
    SWITCH (
        _deptB,
        "Cost Center", _costCenter,
        "Director dept", _director,
        "Service", _service
    )
RETURN
    DIVIDE ( _A, _B )

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi, @Fusilier2 

Based on your description, I have created some measures to achieve the effect you are looking for. Following picture shows the effect of the display.

vyaningymsft_0-1712816166901.png

Measure:

Absent days all % = 
VAR _director =
    CALCULATE ( SUM ( 'Director dept'[Absent Days] ) )
VAR _service =
    CALCULATE ( SUM ( Service[Absent] ) )
VAR _costCenter =
    CALCULATE ( SUM ( 'Cost Center'[Absent] ) )
VAR _dept =
    SELECTEDVALUE ( 'Company dept A'[Dept A] )
VAR _allAbesent = _costCenter + _director + _service
RETURN
    SWITCH (
        _dept,
        "Cost Center", DIVIDE ( _costCenter, _allAbesent ),
        "Director dept", DIVIDE ( _director, _allAbesent ),
        "Service", DIVIDE ( _service, _allAbesent ),
        "Pls Select Dept"
    )
Absent days level % = 
VAR _director =
    CALCULATE ( SUM ( 'Director dept'[Absent Days] ) )
VAR _service =
    CALCULATE ( SUM ( Service[Absent] ) )
VAR _costCenter =
    CALCULATE ( SUM ( 'Cost Center'[Absent] ) )
VAR _deptA =
    SELECTEDVALUE ( 'Company dept A'[Dept A] )
VAR _deptB =
    SELECTEDVALUE ( 'Company dept B'[Dept B] )
VAR _A =
    SWITCH (
        _deptA,
        "Cost Center", _costCenter,
        "Director dept", _director,
        "Service", _service
    )
VAR _B =
    SWITCH (
        _deptB,
        "Cost Center", _costCenter,
        "Director dept", _director,
        "Service", _service
    )
RETURN
    DIVIDE ( _A, _B )

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Thank you. However it looks overly complicated and a bit beyond my skills to be honest.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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