March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
hi there,
Just interesting question here. So I have a transaction table with product , category, amount and another table called category and both table are related on category.
IN transaction table, not all the products have category, only one product id has categor record. What I'm looking for is to sum all the maount of this one product and calculate share by category. and then apply that share of each category to other products in transaciton table.
In following example A1 the main product with categor and share is calculate for each category from total amount of product A1
and same % is now applied to rest of the products to show amount by category (right hand side pivot table)
See image below (i put this as a sample)
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Hi @parry2k,
Could you please mark the proper answer as solution or share the answer if it's convenient for you? That will be a help to the others.
Best Regards!
Dale
Hi Dale,
Thanks for the follow up. I don't think I received the solution yet and hoping someone will help me here.
P
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Hi @parry2k,
If you want to try @danextian 's method, you only need to do one step more, which is adding a calculated column. It works.
NewAmount = CALCULATE ( SUM ( 'Final'[Amount] ), ALLEXCEPT ( 'Final', 'Final'[Product] ) ) * [Share]
Or, you can try this method.
1. Add an index in Query Editor. (must start from 0).
2. Add a new calculated column.
NewCategory = VAR currentIndex = 'Transaction'[Index] RETURN CALCULATE ( VALUES ( 'Transaction'[Category] ), FILTER ( 'Transaction', 'Transaction'[Product] = "A1" && 'Transaction'[Index] = MOD ( currentIndex, 5 ) ) )
3. Create a measure.
Values = VAR ratio = DIVIDE ( CALCULATE ( SUM ( 'Transaction'[Amount] ), 'Transaction'[Product] = "A1" ), CALCULATE ( SUM ( 'Transaction'[Amount] ), FILTER ( ALL ( 'Transaction' ), 'Transaction'[Product] = "A1" ) ), 0 ) RETURN CALCULATE ( SUM ( 'Transaction'[Amount] ), ALLEXCEPT ( 'Transaction', 'Transaction'[Product] ) ) * ratio
4. Create a visual Matrix.
If it helped, please mark the proper answer as solution.
Best Regards!
Dale
By the way, here are my codes
Original
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZYxJCoAwEAT/EvAmYZZE49HtFcH/f8MhBhntQwdS1dO1hpXDGFYLE9k7xWkewjV2sVmkCdao6sxu0WaEIpEzhyU95rd2WnIz6tbE/q/4oISIefkjwZY6pH0rA8rYYgE0Y8vPJ2x1VBAtBe4KlLjfXTc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Product = _t, Category = _t, Amount = _t, Share = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product", type text}, {"Category", type text}, {"Amount", Int64.Type}, {"Share", Percentage.Type}}), #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1), #"Added Custom" = Table.AddColumn(#"Added Index", "Index 1-5", each if Number.From(Text.End(Number.ToText([Index]),1)) = 0 then 5 else if Number.From(Text.End(Number.ToText([Index]),1))<=5 then Number.From(Text.End(Number.ToText([Index]),1)) else Number.From(Text.End(Number.ToText([Index]),1))-5, type number) in #"Added Custom"
Halfway
let Source = original, #"Filtered Rows" = Table.SelectRows(Source, each [Category] <> null and [Category] <> ""), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Amount"}) in #"Removed Columns"
Final
let Source = original, #"Removed Columns" = Table.RemoveColumns(Source,{"Category", "Share", "Index"}), #"Merged Queries" = Table.NestedJoin(#"Removed Columns",{"Index 1-5"},halfway,{"Index 1-5"},"halfway",JoinKind.LeftOuter), #"Expanded halfway" = Table.ExpandTableColumn(#"Merged Queries", "halfway", {"Category", "Share"}, {"Category", "Share"}) in #"Expanded halfway"
Proud to be a Super User!
Hi @parry2k,
I would have three separate queries for this: the original query and two others that reference to the original
Original
if Number.From(Text.End(Number.ToText([Index]),1)) = 0 then 5 else if Number.From(Text.End(Number.ToText([Index]),1))<=5 then Number.From(Text.End(Number.ToText([Index]),1)) else Number.From(Text.End(Number.ToText([Index]),1))-5
This will create a column with numbers that repeat from 1 to 5
Halfway:
Final
Proud to be a Super User!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
133 | |
90 | |
88 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
70 | |
68 |