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
Anonymous
Not applicable

Rows grouped by Max of n-columns

Dear Community !

 

Need your help to created calculated column and get Max of parameters grouped by 'Clients', as shown in below tables.

 

Thanks in advance !Power BI Screen.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi Community, I have found the fix, but since I am new member, can't upload my work. Thanks for all those who responded. !

View solution in original post

6 REPLIES 6
v-yueyunzh-msft
Community Support
Community Support

Hi , @Anonymous 

Thanks for your sample data !

For your need , you need to have the data structure like this:

vyueyunzhmsft_0-1672799659871.png

If you want to create a table , you can use this dax:

Table 2 = ADDCOLUMNS( VALUES('Table'[Client]) ,
 "Max(Topic_1)",var _cur_client = [Client]  var _t = FILTER('Table','Table'[Client]=_cur_client && 'Table'[Topic]="Topic_1") 
 return MAXX(_t, [Value]),
 "Max(Topic_2)",var _cur_client = [Client]  var _t = FILTER('Table','Table'[Client]=_cur_client && 'Table'[Topic]="Topic_2") 
 return MAXX(_t, [Value]),
  "Max(Topic_3)",var _cur_client = [Client]  var _t = FILTER('Table','Table'[Client]=_cur_client && 'Table'[Topic]="Topic_3") 
 return MAXX(_t, [Value])
 )

The result is as follows:

vyueyunzhmsft_1-1672799707366.png

 

You can also put the fields on the visual :

vyueyunzhmsft_2-1672799728799.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Anonymous
Not applicable

Thanks for your response @v-yueyunzh-msft , however, this is a monthly refresh activity and I don't have control on the input file/format. Is there a way you could help on the data which is received as shown please? Thanks in advance !

Hi , @Anonymous 

Do you mean your raw data structure is the 1nd picture you provided?Like this:

vyueyunzhmsft_0-1672821930994.png

If this , when we load it to Power BI , it will look like this:

vyueyunzhmsft_1-1672821957523.png

If this , we need to convert the table to the expected stucture we need , you can put this M code to "Advanced Edirtor" to refer to :

vyueyunzhmsft_2-1672822005712.png

let
    Source = Excel.Workbook(File.Contents("C:\Users\v-yueyzhang\Desktop\mark\1226-1231.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Transposed Table" = Table.Transpose(Sheet1_Sheet),
    #"Filled Down" = Table.FillDown(#"Transposed Table",{"Column1"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Column1] <> "Summary")),
    #"Transposed Table1" = Table.Transpose(#"Filtered Rows"),
    #"Column Name" = Table.ToList(Table.CombineColumns(Table.Transpose( Table.FirstN(#"Transposed Table1",2)),{"Column1", "Column2"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged")),
    Custom1 = Table.RenameColumns(Table.Skip(#"Transposed Table1",2),List.Zip({Table.ColumnNames(#"Transposed Table1"),#"Column Name"}) ),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Custom1, {"Client "}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Attribute.1", type text}, {"Attribute.2", type text}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Attribute.1", "Topic"}, {"Attribute.2", "Param"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Value", Int64.Type}, {"Client ", type text}})
in
    #"Changed Type1"

Then we can get the data table we need:

vyueyunzhmsft_3-1672822032657.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

amitchandak
Super User
Super User

@Anonymous , if topic and param are row values

 

calculate(max([Value]), allexcept(Table, table[client], Table[topic]) )

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Anonymous
Not applicable

Hi Community, I have found the fix, but since I am new member, can't upload my work. Thanks for all those who responded. !

Anonymous
Not applicable

Thanks for your response @amitchandak but the data is sensitive and this form is not allowing me to attach .xlsx file. However, I have found a fix but unable to attach my work (.pbix)

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.