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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rax99
Helper V
Helper V

Calculating measures based on different hierarchy levels

Hi All,

 

I need to know how to perform calculations on different levels of a hierarchy. 

 

Take this matrix as an example;

 

 

Matrix-hierarchies.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Say the Customer Service is Level2 of the hierarchy. (Level 1 being client)

 

The STDEVP.1_Duration is the Standard deviation measure on the duration column. So as per the image above I need to add a new column beside it where it takes the Duration and subtracts the STDEVP.1_duration of the parent level. So in the example above for Customer Service, Total = 22194891 - 406 = 22194485.

 

How do we perform calculations on different levels of the hierarchy?

1 ACCEPTED SOLUTION
rax99
Helper V
Helper V

So I managed to solve this using this DAX:

 

IF (
  ISFILTERED ( AgentTable[EmployeeID] ),
  CALCULATE([STDEVP.1_Duration],ALL(AgentTable[EmployeeID])) - SUM(Duration),
     IF (
        ISFILTERED ( AgentTable[TeamID] ),
        CALCULATE([STDEVP.1_Duration],ALL(AgentTable[TeamID]))- SUM(Duration),
             IF (
                 ISFILTERED ( AgentTable[DeptID] ),
                 CALCULATE([STDEVP.1_Duration],ALL(AgentTable[DeptID]))- SUM(Duration),
                     IF (
                        ISFILTERED ( AgentTable[ClientID]),
                        CALCULATE([STDEVP.1_Duration],ALL(AgentTable[ClientID]))- SUM(Duration)

        )
    )
)

View solution in original post

3 REPLIES 3
theov
Advocate II
Advocate II

Basically we use ISFILTERED for such requirements. However, sometimes your total line might be wrong or empty, in that case you can add HASONEFILTER to detect total line and calculate it differently
Also you might need to have different number formats for each level, in that case you can add FORMAT function. Yet because it is a text function you might have empty lines, so you need to add ISBLANK.

 

This video explains fully the production based on hierarchy level with example 🙂

https://www.youtube.com/watch?v=LV9LqcEmgFc

rax99
Helper V
Helper V

So I managed to solve this using this DAX:

 

IF (
  ISFILTERED ( AgentTable[EmployeeID] ),
  CALCULATE([STDEVP.1_Duration],ALL(AgentTable[EmployeeID])) - SUM(Duration),
     IF (
        ISFILTERED ( AgentTable[TeamID] ),
        CALCULATE([STDEVP.1_Duration],ALL(AgentTable[TeamID]))- SUM(Duration),
             IF (
                 ISFILTERED ( AgentTable[DeptID] ),
                 CALCULATE([STDEVP.1_Duration],ALL(AgentTable[DeptID]))- SUM(Duration),
                     IF (
                        ISFILTERED ( AgentTable[ClientID]),
                        CALCULATE([STDEVP.1_Duration],ALL(AgentTable[ClientID]))- SUM(Duration)

        )
    )
)
v-danhe-msft
Employee
Employee

Hi @rax99 ,

It is hard to reporduce your data structure, could you please post a simple sample to have a test for your problem?

 

Regards,

Daniel He

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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