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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Calculating total cost of sub-tickets

Hello All, 

 

I want to calculate total cost and total sub-request per request (type). I am attaching xls for reference. I have 3 ticket types, request (main), vendor, and sub-request (sub-request has child/parent and sub-request can have multiple languages or tickets). I am trying to calculate total cost without savings for the request (which would be request X number of sub requests) easy version or If I can take the gross word count from request into the sub-request I could get then calculate accurately weighted vs gross word count (weighted is there as language_quote) and i would need to a way to add gross word from request to subrequest or to vendor and then sub-request. 

Either way the idea is to calculate gross X .11 cents minus total_quote (from request) to get cost savings. 

For the life of me I cannot get this to work. Any help would be greatly appreciated: 

Request to Vendor is found in tab 2 (connections tab; it is seperate table in power bi) 

and sub request has parent ID to the right. 

 

Thank you so much for your help. 

Issue_IdKeyIssue_Type_IdIssue_Type_NameGross_WordcountTarget_Language_SelectedUnit_rateFeesLanguage_QuoteWeighted_wordcountTotal_QuoteVendor_QuoteVendorParent_Issue_KeyParent_Issue_Type_Name
342144LOCAT-2920910606Request200 0000€ 111.430   
342158LOCAT-2921913809Vendor0 0000€ 0.0018.96osmicka Hong Kong  
342157LOCAT-2921813809Vendor0 0000€ 0.006.083Dimlight  
342156LOCAT-2921713809Vendor0 0000€ 0.0011.06Latis Global  
342155LOCAT-2921613809Vendor0 0000€ 0.0013.035osmicka Japan  
342154LOCAT-2921513809Vendor0 0000€ 0.005.135Quoted  
342153LOCAT-2921413809Vendor0 0000€ 0.005.309Qloc  
342152LOCAT-2921313809Vendor0 0000€ 0.0012.166Local Heroes  
342151LOCAT-2921213809Vendor0 0000€ 0.0018.128Seamonkeys  
342150LOCAT-2921113809Vendor0 0000€ 0.0010.428Mouse Power  
342164LOCAT-2922513808Sub-Request0POLISH (PL)0.0640.055.30979€ 0.000QlocLOCAT-29214Vendor
342170LOCAT-2923113808Sub-Request0THAI (TH)0.1209.4879€ 0.000osmicka Hong KongLOCAT-29219Vendor
342169LOCAT-2923013808Sub-Request0TRADITIONAL CHINESE (TCH)0.1209.4879€ 0.000osmicka Hong KongLOCAT-29219Vendor
342167LOCAT-2922813808Sub-Request0KOREAN (KR)0.14011.0679€ 0.000Latis GlobalLOCAT-29217Vendor
342165LOCAT-2922613808Sub-Request0PORTUGUESE (BR)0.06505.13579€ 0.000QuotedLOCAT-29215Vendor
342168LOCAT-2922913808Sub-Request0SIMPLIFIED CHINESE (SCH)0.070.16.08379€ 0.000DimlightLOCAT-29218Vendor
342166LOCAT-2922713808Sub-Request0JAPANESE (JP)0.150.113.03579€ 0.000osmicka JapanLOCAT-29216Vendor
342163LOCAT-2922413808Sub-Request0DUTCH (NL)0.140.112.16679€ 0.000Local HeroesLOCAT-29213Vendor
342162LOCAT-2922313808Sub-Request0ITALIAN (IT)0.110.19.43878€ 0.000SeamonkeysLOCAT-29212Vendor
342161LOCAT-2922213808Sub-Request0SPANISH (ES)0.10.18.6979€ 0.000SeamonkeysLOCAT-29212Vendor
342160LOCAT-2922113808Sub-Request0GERMAN (DE)0.120.110.42879€ 0.000Mouse PowerLOCAT-29211Vendor
342159LOCAT-2922013808Sub-Request0FRENCH (FR)0.1280.111.12379€ 0.000Keywords FranceLOCAT-29210Vendor
 
3 REPLIES 3
jennratten
Super User
Super User

Hello - I have reworded your request below.  Can you please let me know if any part of this is not correct and if so, please revise it accordingly?  

Based on the reworded version below, you can accomplish the calculations in Power Query like so:

jennratten_0-1703701777657.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tZVdb6JAFIb/CvHKJi2ZGb4vWUVBUSng3jS9oDrpmqqzK5qm/36HAZQzNpNw0URBjJ73Yc6Zh5eXgWESbJqDx0G8Gvn5E/EI8vgVRjay+Tml/y60PPNPBCF+5C8kvTHGumk0F83r9bGubLndylhUNlyR8Jset+x0+5tcVpR2da+iYOVht/kotJAd37U5P8gxDohxe8bYOnKrGxjvDvvd+5+zXN0G1Z2+N4F1sZRxcd6V2nTP3oq9nGCBBLtvgqEjw+qs06z4WxzlDNBkbPXMsHQsIp4v7Ey3cm0D1DZ71zbEb5/3bCNXJqCy0XdliI5tsfhsU+y1kJ4YLeUIDCJI/xnFpJq4jBYHdvygX3cBCATgvgFIN0XAgl1KqiXsk56kBBv0lrS9FVSXt6fbJq7qJas4ykJtmMQP1Td8OM36bHVa4XgdgqYvsMENeovggJs0sBIhD/1IG+ZhDSCWvPra001Xzv5u60OhSCC2B0CQGiT1x1EerZZ+rI3CaBlkAeca/QwYkBRxlWDzVRr4S204TxsUs52GxiaARVILdJWMAVxDbCVGskrz9XQtluVX2s6LJTkBDksrCOgamQI8GIinpMiiRRJHkygY35qUtU1CTr1Ag5vHAU9H6vAJIRMByxNHSTTzE7/mmCVNg6wrxlXH385L62aoexkGCJWYSpjxmk+sNlzG3VGpSVr9wWmBLoR2lUGAf4mhBIlyP46qqY3yBgVfUfgWMsQecjskQJlQwTIHkDQhSo6MN0coLsgergD10dXtO731oACSI2rJTYN0US3GOOjapO5Lq3TAAf0OHxgSiAUkR9SSm6TBshqQSesSEd2QYH55t2fm9OuTnbalNjkVxw0FNKhD8/of", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Issue_Id = _t, Key = _t, Issue_Type_Id = _t, Issue_Type_Name = _t, Gross_Wordcount = _t, Target_Language_Selected = _t, Unit_rate = _t, Fees = _t, Language_Quote = _t, Weighted_wordcount = _t, Total_Quote = _t, Vendor_Quote = _t, Vendor = _t, Parent_Issue_Key = _t, Parent_Issue_Type_Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Issue_Id", Int64.Type}, {"Key", type text}, {"Issue_Type_Id", Int64.Type}, {"Issue_Type_Name", type text}, {"Gross_Wordcount", Int64.Type}, {"Target_Language_Selected", type text}, {"Unit_rate", type number}, {"Fees", type number}, {"Language_Quote", type number}, {"Weighted_wordcount", Int64.Type}, {"Total_Quote", type number}, {"Vendor_Quote", type number}, {"Vendor", type text}, {"Parent_Issue_Key", type text}, {"Parent_Issue_Type_Name", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Parent Child Level", each if [Issue_Type_Name] = "Request" then 1 else if [Issue_Type_Name] = "Vendor" then 2 else if [Issue_Type_Name] = "Sub-Request" then 3 else -1, Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "ParentIssueKey_Custom", each if [Parent Child Level] = 1 then [Key] else if [Parent_Issue_Key] = "" then null else [Parent_Issue_Key], type text),
    #"Filled Down" = Table.FillDown(#"Added Custom1",{"ParentIssueKey_Custom"}),
    #"Added Custom3" = Table.AddColumn(#"Filled Down", "Request Key", each if [Issue_Type_Name] = "Request" then [Key] else null, type text),
    #"Filled Down1" = Table.FillDown(#"Added Custom3",{"Request Key"}),
    #"Renamed Columns" = Table.RenameColumns(#"Filled Down1",{{"Parent_Issue_Key", "Vendor Key"}}),
    #"Sorted Rows" = Table.Sort(#"Renamed Columns",{{"Request Key", Order.Ascending}, {"Vendor Key", Order.Ascending}, {"Parent Child Level", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Request Key"}, {{"Total_Quote", each List.Sum ( _[Total_Quote] ), Currency.Type }, {"Count of Sub-Requests", each List.Count ( List.Select ( _[Issue_Type_Name], each _ = "Sub-Request" ) ), type number },{"Data", each _, type table}}),
    #"Added Custom2" = Table.AddColumn(#"Grouped Rows", "Gross Cost", each [Total_Quote] * [#"Count of Sub-Requests"], Currency.Type),
    #"Added Custom4" = Table.AddColumn(#"Added Custom2", "Cost Savings", each ( [Gross Cost] * .11 ) - [Total_Quote], Currency.Type)
in
    #"Added Custom4"

To show the word count or any other value from the request on the rows for the vendor or sub-request, if the corresponding cell values for the vendors or sub-requests are null instead of blank, then you can simply fill-down the cells and they will be populated.  This is demonstrated in the "Filled Down" step in the sample query pasted above.

 

There are three values in the issue types column:

  • Request
    • Requests are parents of vendors.
    • In the sample data table provided, there is no key which identifies the relationship between the request and vendor records, but there is only one request present and all vendor records are it's children and will appear in rows directly underneath the request.
  • Vendor
    • Vendors are children of requests and parents of sub-requests.
  • Sub-request
    • Sub-requests are children of vendors and can have sibling relationships with other sub-requests.
    • The parent issue key is in a column to the right

I want to calculate:

  • number of sub-requests per request
  • gross cost for the request
    • This is the total cost without any savings for the request and is calculated by multiplying the total quote amount for the request by the number of sub-requests.
  • cost savings
    • This is calculated by multiplying the gross cost for the request times .11 cents minus the total_quote for the request. 

I would also like to show:

  • The gross word count from request on the row for each sub-request.

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

Anonymous
Not applicable

Hello @jennratten , 

You are a genius 🙂 I have one question, how do I insert this or copy this into powe bi? One at a time or through power query? 

2. I stated the math a bit off:

I want to calculate:

  • number of sub-requests per request (correct) 🙂 This is my main problem on how to add a column w/ this information into the table view
  • gross cost for the request
    • This is the total cost without any savings for the request and is calculated by multiplying the gross word count request by the number of sub-requests and multiplying by .11. in Essence it is total cost = (gross word count * # of sub-requests * .11$) 
  • cost savings
    • This is calculated by gross cost - total quote 

I would also like to show: (with what you have added this is not requred 🙂

  • The gross word count from request on the row for each sub-request.

You are amazing, i have no idea how you did this, if you can let me know how to add this to power bi 🙂 Thank you sooo soo much. 

Lukas 

Hi @Anonymous - apologies for the delayed response.  You are so very welcome!!  To apply this in Power Query, beginning with the table which looks like what was posted in the original message, right-click on the table name and create a reference table.  Then open up the Advanced Editor for that new query and replace the contents with the script below, just change #"Your Table Name Goes Here" to your actual query name being referenced.  

I have also included the changes requested above.  Please have a look!

If this has solved your challenge please consider clicking Accept as Solution and giving it a kudo.  

jennratten_0-1717204128859.png

 

let
Source = #"Your Table Name Goes Here",
    #"Added Custom" = Table.AddColumn(Source, "Parent Child Level", each if [Issue_Type_Name] = "Request" then 1 else if [Issue_Type_Name] = "Vendor" then 2 else if [Issue_Type_Name] = "Sub-Request" then 3 else -1, Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "ParentIssueKey_Custom", each if [Parent Child Level] = 1 then [Key] else if [Parent_Issue_Key] = "" then null else [Parent_Issue_Key], type text),
    #"Filled Down" = Table.FillDown(#"Added Custom1",{"ParentIssueKey_Custom"}),
    #"Added Custom3" = Table.AddColumn(#"Filled Down", "Request Key", each if [Issue_Type_Name] = "Request" then [Key] else null, type text),
    #"Filled Down1" = Table.FillDown(#"Added Custom3",{"Request Key"}),
    #"Renamed Columns" = Table.RenameColumns(#"Filled Down1",{{"Parent_Issue_Key", "Vendor Key"}}),
    #"Sorted Rows" = Table.Sort(#"Renamed Columns",{{"Request Key", Order.Ascending}, {"Vendor Key", Order.Ascending}, {"Parent Child Level", Order.Ascending}}),
    #"Grouped Rows" = Table.Group(#"Sorted Rows", {"Request Key"}, {{"Total_Quote", each List.Sum ( _[Total_Quote] ), Currency.Type }, {"Gross_Wordcount", each List.Sum ( _[Gross_Wordcount] ), Int64.Type }, {"Count of Sub-Requests", each List.Count ( List.Select ( _[Issue_Type_Name], each _ = "Sub-Request" ) ), type number },{"Data", each _, type table}}),
    #"Added Custom2" = Table.AddColumn(#"Grouped Rows", "Gross Cost", each [Gross_Wordcount] * [#"Count of Sub-Requests"] * 0.11, Currency.Type),
    #"Added Custom4" = Table.AddColumn(#"Added Custom2", "Cost Savings", each [Gross Cost] - [Total_Quote], Currency.Type)
in
    #"Added Custom4"

 

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Kudoed Authors