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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
mail2vjj
Helper III
Helper III

Calculation using PATH function Hierarchy

Hello everyone,

 

I am trying to do a calculation based on a hierarchy.

 

I have a table with Names and their Parents and I have created a hierarchy using the PATH function.

 

I have sales data in another table and from that data based on the hierarchy I am trying to calculate the commission.

 

This is the picture of my hierarchy:Screenshot (37).png

 These are all the Paths that I have created and the link to the files is at the end of the message.

Screenshot (36).png

 

 

 

 

This is my Sales Table:

 

DateNameSales
01-01-18A10
01-01-18B20
01-01-18C50
01-01-18D30
01-01-18E40
01-01-18F60
01-01-18G20
01-01-18H30
01-01-18I60
02-01-18A20
02-01-18B40
02-01-18C30
02-01-18D50
02-01-18E10
02-01-18F20
02-01-18G30
02-01-18H30
02-01-18I20

 

 

This is my Total Sales Table along with the Desired Commission results:

NameSalesCommission 1Commission 2
A301014
B6012.513.9
C8014.514.5
D801511
E5055
F8088
G5055
H6066
I8088

 

I have 2 ways to calculate commission.

 

First:

Commission on own sale (10%) + Commission for every sub-branch of the hierarchy (5%).

 

For eg. For B, own sale is 60 and sub-branch sales for D and E are 80 & 50 respectively, so total is 130.

So Commission for B is (60*10%) + (130*5%) = 12.5

 

For eg. For D, own sale is 80 and sub-branch sales for H and I are 60 & 80 respectively, so total is 140.

So Commission for B is (80*10%) + (140*5%) = 15

 

Second:

Commission on own sale (10%) + Commission from every sub-branch (5%) and sub-sub branches of the hierarchy (1%).

 

For Eg. For A, own sale is 30, sub-branch sales for B and C are 140 and all other sub-sub-branches (D,E,F,G,H,I) total is 400

So Commission for A is (30*10%) + (140*5%) + (400*1%) = 14

 

Similarly Commission for B, Own Sale is 60, sub-branch sales for D and E are 80 & 50 respectively and sub-sub-branch sale for H and I are 60 and 80 respectively.

So Commission for B is (60*10%) + (130*5%) + (140*1%) = 13.9

 

Ths following is the link to my Excel file and the PBIX file.

https://1drv.ms/f/s!Ap0qSKP-4qpThCc1sSXanmibgIff

 

It would be great if anyone can help me with this.

 

Thank you,

 

Vishesh Jain

30 REPLIES 30

Hi @mail2vjj

 

Could you add rows with zero sales for Names missing in a month?

 

This will resolve the issue...of getting share for parent when they dont have sales but their children have it

 

For example I just added the last row in image below and I start getting A's share for B which is the Direct Child

 

vj.png

Hi @Zubair_Muhammad

 

I am afraid I cannot do that.

 

This is the sales sheet and there will only be entries for the actual sales made.

This sheet will be automatically generated by a software.

 

Also adding 0 sales to my sheet for every single name that exists, will add rows to excel that we don't really need.

Morever, after a certain number of rows, excel slows down and becomes inefficient, so I don't know how wise it will be if we add rows that we don't need.

 

I am sure you are aware of this.

 

Sorry for throwing another stone in your way.

 

Vishesh Jain.

Is there some way to add the rows with 0 sales using the Query Editor?

Hi @mail2vjj

 

Sorry for late reply

 

One way of adding the missing row is using a Calculated Table

 

See the attached file.

Then you have to do all the MEASURES based on this new Table

 

SalesNew =
VAR mytable =
    CROSSJOIN (
        SELECTCOLUMNS ( Sales, "Name", [Name] ),
        SELECTCOLUMNS (
            Sales,
            "date", [Date],
            "Location", [Location],
            "Product", [Product]
        )
    )
RETURN
    ADDCOLUMNS (
        mytable,
        "Sales", LOOKUPVALUE (
            Sales[Sales],
            Sales[Date], [date],
            Sales[Location], [Location],
            Sales[Name], [Name],
            Sales[Product], [Product]
        )
    )

Hi @Zubair_Muhammad

 

Thanks for hanging in there with me until now and taking the time to work on my problem.

 

I just saw your solution and I see some problems with it.


One is, as even you know, the model is getting unnecessarily big, since it is creating a row for every single combination of Date, Product, Location and Name.


So if more columns are added in the future, the number of rows will increase exponentially which will slow down the model. I am sure you saw that for only a handful of rows of sales data, the new model has created around 400 rows.

 

Second is that, there are multiple rows being created for the same combination of sales, which is completely wrong.

Screenshot (55)_LI.jpg

 

 

As you can see for 1st Feb 2018, Product 2, in USA for B 3 rows have been created, which will give a bloated up result.

 

For these reasons I am not in the favor of adding rows with 0 sales.

 

Please let me know if you can still come up with some other way to fix this.

 

Thank you for all your help.

 

Vishesh Jain

Hi @mail2vjj

 

Hi Vishesh,

 

I suggest creating a new post with this problem.....

 

I hope majority of your problems have been resolved...only this part is giving trouble

 

Wish you all the best

@mail2vjj

 

I am not able to get Date Hierarchy to work either Smiley Sad

 

Hi @Zubair_Muhammad

 

I can try to manage some how if the date Hierarchy is not working.

 

Is it possible to get the commission calcualtions for the parent-child correclty?

 

I have posted another question in the community if you would like to take a dig at it, but it is more realted to Power Query and M.

 

I don't know if it is up your alley or not.

 

https://community.powerbi.com/t5/Desktop/Generate-Columns-Automatically-for-Hierarchy-and-PATH/m-p/3...

 

Thank you so much for taking the time to help me with everything.

 

Thank you,

 

Vishesh Jain

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.