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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
untapjoseph
Helper I
Helper I

Grouping table rows and sorting

Hello - i think this is best placed as a power query issue. 

 

I am trying to order a table, but the issue is that the rows need to be grouped also.  An example of the data is as follows:

 

TransactionFundValueVariableDate
ATotal105001/03/2022
AX55.501/03/2022
AY3201/04/2022
AZ2601/03/2022
BTotal34501/06/2022
BW3301/06/2022

 

The table visual needs to display the Transaction fund Total with each individual fund as rows below it, with all the groups of transaction sorted by the date. A simple way to do this would be to use a matrix and have the transaction as a sub-total, but a couple of the columns are aggregated and so the source data row needs to be use. 

 

In theory, I could create a custom column that applies the Total date to all other funds within the same transaction and then concatenate column with the transaction to create a index identifyer. But i am open to any thoughts on how this can be best approached. 

 

Many thanks in advance

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @untapjoseph 

 

Does your current table have the Total rows as shown in the example? If so, I can transform it into the following table (Date is sorted ascendingly in each Transaction group and the Total row is on the top of each group).

vjingzhang_0-1667982617394.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUQrJL0nMAdKGBkDCFEQYGOobGOsbGRgZKcXqQBRFgORAWM8Uu4JIIDYGYiOotAmqdBRUygxTtxOSG0AmmMBsMENVEw6VN0aTjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Transaction = _t, Fund = _t, Value = _t, Variable = _t, Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Transaction", type text}, {"Fund", type text}, {"Value", Int64.Type}, {"Variable", type number}, {"Date", type date}}, "en-GB"),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Fund Sort", each if [Fund] = "Total" then 0 else 1),
    #"Grouped Rows" = Table.Group(#"Added Conditional Column", {"Transaction"}, {{"All Data", each _, type table [Transaction=nullable text, Fund=nullable text, Value=nullable number, Variable=nullable number, Date=nullable date, Fund Sort=number]}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows", {"All Data", each Table.Sort(_, {{"Fund Sort", Order.Ascending}, {"Date", Order.Ascending}})}),
    #"Expanded All Data" = Table.ExpandTableColumn(Custom1, "All Data", {"Fund", "Value", "Variable", "Date", "Fund Sort"}, {"Fund", "Value", "Variable", "Date", "Fund Sort"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded All Data",{"Fund Sort"})
in
    #"Removed Columns"

 

However, when I apply it to the report and add columns to a table visual, it doesn't remain this sorting when displaying. You may have a try. 

 

If I didn't understand it correctly, can you please show the expected output format with the example data? 

 

Best Regards,
Community Support Team _ Jing

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors