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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
naifAhmedB
Helper II
Helper II

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

 

 1.PNG

 

How can I do that?

1 ACCEPTED SOLUTION
edhans
Super User
Super User

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:

edhans_0-1609265372836.png

It will turn this:

edhans_1-1609265405963.png

 

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

edhans_2-1609265431872.png

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.

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

2 REPLIES 2
edhans
Super User
Super User

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:

edhans_0-1609265372836.png

It will turn this:

edhans_1-1609265405963.png

 

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

edhans_2-1609265431872.png

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.

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
amitchandak
Super User
Super User

@naifAhmedB , Create a new column like

 

if([Branch code] ="RiyadhSulimania", "Retail", "Non Retail")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.