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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
jcastr02
Post Prodigy
Post Prodigy

% of row total into columns

Hello I have the below data arranged by store number and total by Later, tomorrow, and waiter.  How could I rearrange to the desired result in power Query where I need the % of row total for each store.

 CURRENT    DESIRED 
STOREPRIORITY_VALUETTL STORELaterTomorrowWaiter
13Later36627 1361.0%32.9%6.0%
13Tomorrow19750 2373%18%9%
13Waiter3624     
23Later5197     
23Tomorrow1275     
23Waiter608     
1 ACCEPTED SOLUTION
AnushaSri
Advocate II
Advocate II

I have selected Priority_Values column and choose pivot columns

View solution in original post

4 REPLIES 4
AnushaSri
Advocate II
Advocate II

I have selected Priority_Values column and choose pivot columns

dufoq3
Super User
Super User

Hi @jcastr02, different approach here:

 

Result

dufoq3_0-1715364977378.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRW0lHySSxJLQLSxmZmRuZKsTpQ4ZD83PyiovxyINPQ0tzUACETnpgJ02FkAhY2QjbHFKgcIYpsjJG5KUICboqZgYVSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [STORE = _t, PRIORITY_VALUE = _t, TTL = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"STORE", Int64.Type}, {"TTL", type number}}),
    GroupedRows = Table.Group(ChangedType, {"STORE"}, {{"All", each 
        [ a = List.Sum([TTL]),
          b = Table.TransformColumns(_, {{"TTL", (x)=> x / a, Percentage.Type}}),
          c = Table.SelectColumns(b, {"PRIORITY_VALUE", "TTL"}),
          d = Table.PromoteHeaders(Table.FromColumns( {{"STORE", [STORE]{0}?}} & Table.ToRows(c))),
          e = Table.TransformColumnTypes(d, {{"STORE", Int64.Type}} & List.Transform([PRIORITY_VALUE], (x)=> {x, Percentage.Type}))
        ][e], type table}}),
    CombinedAll = Table.Combine(GroupedRows[All])
in
    CombinedAll

 


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

AnushaSri
Advocate II
Advocate II

Hi, 

Please mark this as a solution and give Kudos if it resolves your issue.

Add these steps to your Power Query to achieve what you are looking for,

#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Priority_value]), "Priority_value", "Total"),
#"Inserted Sum" = Table.AddColumn(#"Pivoted Column", "Addition", each List.Sum({[Later], [Tomorrow], [Waiter]}), Int64.Type),
#"Inserted Percent Of" = Table.AddColumn(#"Inserted Sum", "P1", each [Later] / [Addition], Percentage.Type),
#"Inserted Percent Of1" = Table.AddColumn(#"Inserted Percent Of", "P2", each [Tomorrow] / [Addition], Percentage.Type),
#"Inserted Percent Of2" = Table.AddColumn(#"Inserted Percent Of1", "P3", each [Waiter] / [Addition], Percentage.Type),
#"Removed Columns" = Table.RemoveColumns(#"Inserted Percent Of2",{"Later", "Tomorrow", "Waiter", "Addition"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"P1", "Later"}, {"P2", "Tomorrow"}, {"P3", "Waiter"}})

@AnushaSri  Thank you!

For the first step to pivot the column - which columns did you select and which option did you pick?

Unpivot Columns

Unpivot Other Columns

Unpivot Only Selected Columns

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors