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 count the number of prices that match the Mode.  Thanks in advance!

Product  Amazon  Walmart Bestbuy  Home Depot Lowes Target Mode
1200200150125300275200
250757575856075
3300300600450400500300
425506060604560
510010075756585100

 

 

  • 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

     

3 Replies

  • Arul's avatar
    Arul
    Super User

    jboschee ,

    Could you share the formula for mode calculation and mention which price column to compare Mode?

    Thanks,

    • jboschee's avatar
      jboschee
      Frequent Visitor

      Hi Arul ,

      Here's the formula in excel =MODE(C2:H2).  Part of my question was how to get the mode in PBI and then do a count of the mode occurances as well.

  • 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