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
ifzalahmed
New Member

Hierarchal level Calculation - Different DAX for Each Level

Hello,

 

I am new Power BI and not really versed with DAX formula. I am facing a small problem. I have phrased my question in google in many ways but maybe I couldn't express what I want. 

so let me explain this with an example ; 

I have a table where I want to calculate the difference in the cost with last year at each product level but at the category level, I don't want to follow the same formula instead I want in category level to sum the differences calculated at each product level in previous steps.

so for Prod A, B & C, Cost Variance is : (Qty TY * Cost TY) - (Qty LY - Cost LY )

while at category level the cost variance is the sum of Variances of A,B, & C.

 This Year QtyThis YearCost per UnitThis Year QtyThis YearCost per UnitCost Variance  
Cat 1                   (12.00)  
Prod A                  3.00              2.00                  2.00               1.50                 (3.00)  
Prod B                  4.00              1.50                  3.00               2.00                        -    
Prod C                  6.00              3.50                  4.00               3.00                 (9.00)  
Cat 2                     11.50  
Prod D                  3.00              1.70                  5.00               1.20                   0.90  
Prod E                  2.00              2.50                  6.00               2.60                 10.60  

 

 

 

2 REPLIES 2
ifzalahmed
New Member

Thank you, Amit. unfortunately, it didn't work for me. let me explain what I want from this measure.
My measure has two steps:

1. On Product Level I want to return zero if the qty of product in previous month is zero and if its qty is not zero then I want to calculate the difference in Unit Cost ( current month - previous month ) and multiply it by the current month qty.

2. secondly on Category Level  I want to just sum up the cost difference that is calculated for each product in the same category in the previous step.

and Ultimatly I want to calculate Cost Variance per Product and per-category at each level.

amitchandak
Super User
Super User

@ifzalahmed , You need isinscope plus x function and values

 

Assuming these are measures

[Qty TY] , [Cost TY] , [Qty LY] , [Cost LY]

Example of sumx

sumx(values(Table[Category]), ([Qty TY] * [Cost TY]) - ([Qty LY] - [Cost LY] ))

 

For insinscope , refer https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.