cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
bnlguy1493
Frequent Visitor

Calculate Sum of Expenses by Manager

Hi folks,

 

I'm looking to calculate the sum of expenses (Ex. VAT Cost) by line managers as well as each individual travel type. I have two tables: The first "Expense" table contains the travel expense including and excluding travel costs by each colleague. The second is a "name" table containing the names of colleagues and line managers. I have constructed a hierarchy path and a corresponding matrix table showing how much each colleague has spent and the matrix is also showing how much money (Ex. VAT Cost) is spent by each manager. However, you can see that the matrix is also displaying the expenses of the employees. I have tried multiple ways, but I can't figure out how to only display the names of the managers alone. As you can see from the matrix, there are four managers -- "Samira Mishra, Darien Jacobse, Irene Monet and Hildr Tennyson." I tried filtering using the "Is Manager?" column, but the matrix shows the sum of expenses for only that manager, without including the expenses of their subordinates. If I separately calcualate the group expenses (Ex. VAT Cost) using a calculate and sum command (in a calculated column), I get the correct expenses by each manager, but incorrect when i filter by travel type. 

Matrix: 

 

Name Table: 

 

Colleague IDColleague NameLine Manager IDPathLevel1IDLevel2IDLevel3IDLevel4IDLevel1NameLevel2NameLevel3NameLevel4NameIs Manager?  
232072Irene Monet201854201854|232072201854232072  Samira MishraIrene Monet  TRUE  
264976Timon Matthews232072201854|232072|264976201854232072264976 Samira MishraIrene MonetTimon Matthews FALSE  
A10637Mohini Patel232072201854|232072|A10637201854232072A10637 Samira MishraIrene MonetMohini Patel FALSE  
299333Vasia Bellincioni3783201854|281247|3783|2993332018542812473783299333Samira MishraDarien JacobseHildr TennysonVasia BellincioniFALSE  
295930Amilcar Adam3783201854|281247|3783|2959302018542812473783295930Samira MishraDarien JacobseHildr TennysonAmilcar AdamFALSE  
D18660Dileep Ibrahimovic281247201854|281247|D18660201854281247D18660 Samira MishraDarien JacobseDileep Ibrahimovic FALSE  
299391Rosalee Jacques281247201854|281247|299391201854281247299391 Samira MishraDarien JacobseRosalee Jacques FALSE  
3783Hildr Tennyson281247201854|281247|37832018542812473783 Samira MishraDarien JacobseHildr Tennyson TRUE  
235419Emanuel Hardwick281247201854|281247|235419201854281247235419 Samira MishraDarien JacobseEmanuel Hardwick FALSE  
7789Emely Bentley281247201854|281247|77892018542812477789 Samira MishraDarien JacobseEmely Bentley FALSE  
281247Darien Jacobse201854201854|281247201854281247  Samira MishraDarien Jacobse  TRUE  
289162Chander Kaur3783201854|281247|3783|2891622018542812473783289162Samira MishraDarien JacobseHildr TennysonChander KaurFALSE  
201854Samira Mishra201854201854201854   Samira Mishra   TRUE  
241708Dervla Jarrett232072201854|232072|241708201854232072241708 Samira MishraIrene MonetDervla Jarrett FALSE  

Expense Table: (Partial)

Name Table: 

 

Colleague IDColleague NameLine Manager IDPathLevel1IDLevel2IDLevel3IDLevel4IDLevel1NameLevel2NameLevel3NameLevel4NameIs Manager?  
232072Kiran Sharma201854201854|232072201854232072  Xi Fung Kiran Sharma  TRUE  
264976Blunt Smith232072201854|232072|264976201854232072264976 Xi Fung Kiran SharmaTimon Matthews FALSE  
A10637Mohini Patel232072201854|232072|A10637201854232072A10637 Xi Fung Kiran SharmaMohini Patel FALSE  
299333Suresh Kaladi3783201854|281247|3783|2993332018542812473783299333Xi FungSmith WessonHildr TennysonVasia BellincioniFALSE  
295930Ameen Khan3783201854|281247|3783|2959302018542812473783295930Xi FungSmith WessonHildr TennysonAmilcar AdamFALSE  
D18660Clark Sasson281247201854|281247|D18660201854281247D18660 Xi FungSmith WessonDileep Ibrahimovic FALSE  
299391Rosafeld Jacqueline281247201854|281247|299391201854281247299391 Xi FungSmith WessonRosalee Jacques FALSE  
3783Blessen George281247201854|281247|37832018542812473783 Xi FungSmith WessonHildr Tennyson TRUE  
235419June Sun281247201854|281247|235419201854281247235419 Xi FungSmith WessonEmanuel Hardwick FALSE  
7789Bently Royce281247201854|281247|77892018542812477789 Xi FungSmith WessonEmely Bentley FALSE  
281247Smith Wesson201854201854|281247201854281247  Xi FungDarien Jacobse  TRUE  
289162Chand Persh3783201854|281247|3783|2891622018542812473783289162Xi FungSmith WessonHildr TennysonChander KaurFALSE  
201854Xi Fung201854201854201854   Xi Fung   TRUE  
241708Ghulam Azad232072201854|232072|241708201854232072241708 Samira MishraIrene MonetDervla Jarrett FALSE  

 

Expense Table: (Partial)

 

First NameMiddle InitialLast NameInc. VAT CostEx. VAT CostVAT CostFull NameType of Travel
SmithM.Wesson£885£738147Smith WessonFlight
KiranK.Sharma£71£5912Kiran SharmaPersonal Car
Blessen George£94£7816Blessen GeorgeBusiness Car
BluntL.Smith£99£8316Blunt SmithBusiness Car
Jun Sun£70£5812June SunPersonal Car
Blessen George£598£498100Blessen GeorgeHotel
Blessen George£40£337Blessen GeorgePersonal Car
Xi Fung£614£512102Samira MishraFlight
ClarkD.Sasson£55£469Clark SassonPersonal Car

 

 

 

Just to summarize again, I want to display the expenses by each manager, taking into account the expenses by their subordinates as well. Thanks for the help!

1 ACCEPTED SOLUTION

@bnlguy1493 ,

Measure:

__amt = 
VAR amt = SUM ( Expense[Ex. VAT Cost] )
VAR nameInScope =
    SWITCH (
        TRUE (),
        ISINSCOPE ( 'Name'[Level4Name] ), SELECTEDVALUE ( 'Name'[Level4Name] ),
        ISINSCOPE ( 'Name'[Level3Name] ), SELECTEDVALUE ( 'Name'[Level3Name] ),
        ISINSCOPE ( 'Name'[Level2Name] ), SELECTEDVALUE ( 'Name'[Level2Name] ),
        SELECTEDVALUE ( 'Name'[Level1Name] )
    )
VAR isMgr =
    CALCULATE (
        SELECTEDVALUE ( 'Name'[Is Manager?] ),
        'Name'[Colleague Name] = nameInScope
    )
RETURN
    IF ( isMgr, amt )

Columns:

Level1Name = LOOKUPVALUE('Name'[Colleague Name], 'Name'[Colleague ID], PATHITEM('Name'[Path],1,TEXT))

Next ones with the same pattern:

Level2Name = IF( PATHLENGTH('Name'[Path]) >=2, LOOKUPVALUE('Name'[Colleague Name], 'Name'[Colleague ID], PATHITEM('Name'[Path], 2, TEXT)), 'Name'[Level1Name])
NodeDepth = PATHLENGTH('Name'[Path])
Path = PATH('Name'[Colleague ID], 'Name'[Line Manager ID])

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

4 REPLIES 4
bnlguy1493
Frequent Visitor

@ Thanks much for sharing your code!

bnlguy1493
Frequent Visitor

Hi @ERD  thanks! Yes, that is exactly what I want to achieve -- I tried to filter by the "Is Manager?" True/False filter but it was throwing up incorrect values. How did you do that? 

@bnlguy1493 ,

Measure:

__amt = 
VAR amt = SUM ( Expense[Ex. VAT Cost] )
VAR nameInScope =
    SWITCH (
        TRUE (),
        ISINSCOPE ( 'Name'[Level4Name] ), SELECTEDVALUE ( 'Name'[Level4Name] ),
        ISINSCOPE ( 'Name'[Level3Name] ), SELECTEDVALUE ( 'Name'[Level3Name] ),
        ISINSCOPE ( 'Name'[Level2Name] ), SELECTEDVALUE ( 'Name'[Level2Name] ),
        SELECTEDVALUE ( 'Name'[Level1Name] )
    )
VAR isMgr =
    CALCULATE (
        SELECTEDVALUE ( 'Name'[Is Manager?] ),
        'Name'[Colleague Name] = nameInScope
    )
RETURN
    IF ( isMgr, amt )

Columns:

Level1Name = LOOKUPVALUE('Name'[Colleague Name], 'Name'[Colleague ID], PATHITEM('Name'[Path],1,TEXT))

Next ones with the same pattern:

Level2Name = IF( PATHLENGTH('Name'[Path]) >=2, LOOKUPVALUE('Name'[Colleague Name], 'Name'[Colleague ID], PATHITEM('Name'[Path], 2, TEXT)), 'Name'[Level1Name])
NodeDepth = PATHLENGTH('Name'[Path])
Path = PATH('Name'[Colleague ID], 'Name'[Line Manager ID])

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

ERD
Super User
Super User

Hi @bnlguy1493 , is this the result you want to achieve?

ERD_0-1695824322289.png

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors