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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Power Query help!

Hi guys

 

I'm very (very) new to Power Query, trying to teach myself and have a question I'm hoping someone can help with.

 

I have a set of data that has 5 Columns (Account, Channel, SKU, Date and Value).

 

Within Account, I have 4 different items - Sales, Promotional Spend, Cost of Goods and Logistics Cost, and overall have c.30,000 rows of data.

 

I want to be able to calculate say, promotional spend as a % of Sales as it's own row for each eventuality (eg for arguments sake I have 10 channels, 10 SKUs and 10 dates, so 1,000 potential eventualities) - so I want a promotional spend % of sales for each of these.

 

I want it as it's own row so I can then pivot it in Excel to be able to show Promotional spend as a % of sales in a pivot table over time without having to use excel formulae to calculate it. 

 

Is that possible?!

 

Thanks!

Tom

1 ACCEPTED SOLUTION

Result

dufoq3_0-1711382019538.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZOxDoIwEIZfxTA3yt21qCPBByBhcDAOGBlIkBp18uklMZE/UmnrVIb78l/+7zgckvxSP22fqKSqu+Y+vLuyKHh4zYpWnLIMn6yYeZmmyVHNANkIiJIAYA2AiHd8M44TKyF/wBY3IvZHUBqdQQSI6Ml8ebMX+2htX3eL6tr0Z3fFru3mUCjb6CwKXf+fCgo0UxQKLrSJWxitaGUig1HQR+e+Od3bR4M+84K/nEjAePbrYH4j0L8Z/hPtJzZ4x0ziJ6BtUiwBGVgyXNQMgL26EpxSpi07GpsjM+f1hrHuyw9jwYGJRFFGHIlSxESy6Oft8/gC", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Channel = _t, Account = _t, SKU = _t, Date = _t, Value = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Currency.Type}}, "en-US"),
    PivotedColumn = Table.Pivot(ChangedType, List.Distinct(ChangedType[Account]), "Account", "Value"),
    Ad_Ratio = Table.AddColumn(PivotedColumn, "Ratio", each [Promotional Spend] / [Sales], Percentage.Type)
in
    Ad_Ratio

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Yes here you go inc the final few rows where I've added how I want the Promo % to look. Thank you!

 

ChannelAccountSKUDateValue
AmazonSalesDPCC25/1/20232,222.00
AmazonSalesDPCC26/1/20233,322.00
AmazonSalesDPCC27/1/2023333.00
AmazonSalesDPCC28/1/202312,312.00
AmazonSalesDPCC29/1/20233,123.00
AmazonSalesDPCC210/1/202312,312.00
AmazonSalesDPCC211/1/2023134.00
AmazonPromotional SpendDPCC25/1/2023123.00
AmazonPromotional SpendDPCC26/1/2023546.00
AmazonPromotional SpendDPCC27/1/2023123.00
AmazonPromotional SpendDPCC28/1/2023421.00
AmazonPromotional SpendDPCC29/1/2023456.00
AmazonPromotional SpendDPCC210/1/20234,521.00
AmazonPromotional SpendDPCC211/1/20232.00
WebsiteSalesDAC225/1/202332.00
WebsiteSalesDAC226/1/202312,312.00
WebsiteSalesDAC227/1/20235,324.00
WebsiteSalesDAC228/1/20233,213.00
WebsiteSalesDAC229/1/20231,234.00
WebsiteSalesDAC2210/1/2023546.00
WebsiteSalesDAC2211/1/2023234.00
WebsitePromotional SpendDAC225/1/20232.00
WebsitePromotional SpendDAC226/1/2023123.00
WebsitePromotional SpendDAC227/1/2023123.00
WebsitePromotional SpendDAC228/1/202353.00
WebsitePromotional SpendDAC229/1/20231.00
WebsitePromotional SpendDAC2210/1/202335.00
WebsitePromotional SpendDAC2211/1/202326.00
AmazonPromo spend as % of salesDPCC25/1/20236%
AmazonPromo spend as % of salesDPCC26/1/202316%
AmazonPromo spend as % of salesDPCC27/1/202337%
AmazonPromo spend as % of salesDPCC28/1/20233%
AmazonPromo spend as % of salesDPCC29/1/202315%
AmazonPromo spend as % of salesDPCC210/1/202337%
AmazonPromo spend as % of salesDPCC211/1/20231%

Result

dufoq3_0-1711382019538.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZOxDoIwEIZfxTA3yt21qCPBByBhcDAOGBlIkBp18uklMZE/UmnrVIb78l/+7zgckvxSP22fqKSqu+Y+vLuyKHh4zYpWnLIMn6yYeZmmyVHNANkIiJIAYA2AiHd8M44TKyF/wBY3IvZHUBqdQQSI6Ml8ebMX+2htX3eL6tr0Z3fFru3mUCjb6CwKXf+fCgo0UxQKLrSJWxitaGUig1HQR+e+Od3bR4M+84K/nEjAePbrYH4j0L8Z/hPtJzZ4x0ziJ6BtUiwBGVgyXNQMgL26EpxSpi07GpsjM+f1hrHuyw9jwYGJRFFGHIlSxESy6Oft8/gC", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Channel = _t, Account = _t, SKU = _t, Date = _t, Value = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Currency.Type}}, "en-US"),
    PivotedColumn = Table.Pivot(ChangedType, List.Distinct(ChangedType[Account]), "Account", "Value"),
    Ad_Ratio = Table.AddColumn(PivotedColumn, "Ratio", each [Promotional Spend] / [Sales], Percentage.Type)
in
    Ad_Ratio

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

dufoq3
Super User
Super User

Hi @Anonymous, it is possible, but could you privide sample data as table so we can copy/paste and expected result based on sample data?


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.