Forum Discussion

jboschee's avatar
jboschee
Frequent Visitor
3 years ago
Solved

Mode Measure

Hi ! I'm trying to add a Mode measure into my prices matrix grid similiar to what I have below in excel.  My matrix is set up the same way in pbi.  It would be great if I could also find a way to ...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi , jboschee 

    According to your description, you want to get the [Mode] column in Power BI.Right?

    For your need , i recommend you to realize it in Power Query Editor.

    You can put this M code in the "Advanced Editor" in Power Query Editor:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VY7BDcAwCAN34Z0HECDdBbH/Gg3QRsrnZGGDcQeCAYx4SFpk3Zw9XwoxHHjrMpdeeBKGlZlnq2lFqTUprdhJycv6n7Qb0o1pU3+Fd7F9xREv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product " = _t, #" Amazon " = _t, #" Walmart " = _t, #"Bestbuy " = _t, #" Home Depot " = _t, #"Lowes " = _t, #"Target " = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product ", Int64.Type}, {" Amazon ", Int64.Type}, {" Walmart ", Int64.Type}, {"Bestbuy ", Int64.Type}, {" Home Depot ", Int64.Type}, {"Lowes ", Int64.Type}, {"Target ", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", (x)=> Table.Sort(Table.AddColumn(Table.FromColumns({List.Skip(Record.ToList(x))}),"count",(y)=> Table.RowCount(Table.SelectRows(Table.FromColumns({List.Skip(Record.ToList(x))}),(z)=>z[Column1]=y[Column1])) ,type number    ),{"count",1})[Column1]{0}        )
    in
        #"Added Custom"

    Then we can meet your need:

     

    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