Forum Discussion

naifAhmedB's avatar
naifAhmedB
Helper II
5 years ago
Solved

segmenting the values for different names

Hi,

 

I have values for three branch code as the attached photo.

 

I want to show rename or make the branch code to appear as Retail for RiyadhSulimania = 334 visitors

and non retail for the other two with 46 visitors

 

 

 

How can I do that?

  • In Power Query naifAhmedB add a new custom column. Use this formula

    if [BranchCode] = "RiyadhSulimania" then "Retail" else "Non-Retail"

     

    Then go to the Group button and group by the Type:

    It will turn this:

     

    Into this (I used a,b,c not real names)

    The full M code to see this is here:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTJUitWJVkoCsozArGQgy1gpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Branch Code" = _t, Visitors = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Visitors", Int64.Type}}),
        #"Added Type" = Table.AddColumn(#"Changed Type", "Type", each if [Branch Code] = "a" then "Retail" else "Non-Retail"),
        #"Grouped Rows" = Table.Group(#"Added Type", {"Type"}, {{"Visitors", each List.Sum([Visitors]), type nullable number}}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Grouped Rows",{{"Type", type text}})
    in
        #"Changed Type1"

     

    How to use M code provided in a blank query:
    1) In Power Query, select New Source, then Blank Query
    2) On the Home ribbon, select "Advanced Editor" button
    3) Remove everything you see, then paste the M code I've given you in that box.
    4) Press Done
    5) See this article if you need help using this M code in your model.

     

    If you need more help, please provide usable data and a sample of what your output needs to be.

    How to get good help fast. Help us help you.
    How to Get Your Question Answered Quickly - Give us a good and concise explanation
    How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.

     

     

2 Replies

  • edhans's avatar
    edhans
    Community Champion

    In Power Query naifAhmedB add a new custom column. Use this formula

    if [BranchCode] = "RiyadhSulimania" then "Retail" else "Non-Retail"

     

    Then go to the Group button and group by the Type:

    It will turn this:

     

    Into this (I used a,b,c not real names)

    The full M code to see this is here:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTJUitWJVkoCsozArGQgy1gpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Branch Code" = _t, Visitors = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Visitors", Int64.Type}}),
        #"Added Type" = Table.AddColumn(#"Changed Type", "Type", each if [Branch Code] = "a" then "Retail" else "Non-Retail"),
        #"Grouped Rows" = Table.Group(#"Added Type", {"Type"}, {{"Visitors", each List.Sum([Visitors]), type nullable number}}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Grouped Rows",{{"Type", type text}})
    in
        #"Changed Type1"

     

    How to use M code provided in a blank query:
    1) In Power Query, select New Source, then Blank Query
    2) On the Home ribbon, select "Advanced Editor" button
    3) Remove everything you see, then paste the M code I've given you in that box.
    4) Press Done
    5) See this article if you need help using this M code in your model.

     

    If you need more help, please provide usable data and a sample of what your output needs to be.

    How to get good help fast. Help us help you.
    How to Get Your Question Answered Quickly - Give us a good and concise explanation
    How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.