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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Split column into multiple rows and equally divide a value grouped by the splitted column

Hi everyone, 

 

I would like to split a column with a delimeter into multiple rows and divide the value by the count of rows splitted into. 

 

Like in a screenshot I attached , I would like to split the cities and then divide sales among them equallyCapture.PNG

3 REPLIES 3
CheenuSing
Community Champion
Community Champion

Hi @Anonymous,

 

Based on the requirement do the following steps.

 

1. Load the data.

2. Go to Edit Query of the table

3. Use Split Column to split the column containing City to as many columns as delimited by "," (comma).

    ( Assumption made is Each Country will have three cities separated by comma ).

 

4. The table will have 3 columns called City.1 City.2 City.3

5. Select the 3 city columns and from Transform Tab of the ribbon Select UnPivot Columns

6. You will then get each Continent, Country, City as individual rows.

7. Remove the column Attribute

8. Now do Group By from Transform column to find the count of rows by Continent, Country.

       

Capture1.JPG

 

9. Expand the Table column you get at the end of above group by operation.

10.  Rename the columns

11. Add a custom column Divided Sales = Sales Original / Count Rows

12.  Change the type of Divided Sales as WholeNumber

 

13. Now plot the Matrix table

 

Capture.JPG

 

 

You will get the desired output.

 

This kind of transformation is best done in Power Query than DAX.

 

If this works for you accept this as Solution and also give KUDOS.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!
LivioLanzo
Solution Sage
Solution Sage

You easily do it like this:

 

let
    Source = Table.FromRecords( 
                    { [Continent = "Europe", Country = "Germany", City="Munich,Berlin,Cologne", Sales=300] }, 
                    type table [Continent = Text.Type, Country = Text.Type, City = Text.Type, Sales = Number.Type] ),
    
    Trnsfm = Table.TransformColumns( Source, {"City", each Text.Split(_,","), type list}),
    #"Added Custom" = Table.AddColumn(Trnsfm, "Sales2", each [Sales] / List.Count( [City] ), type number ),
    #"Expanded City" = Table.ExpandListColumn(#"Added Custom", "City"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded City",{"Sales"})
in
    #"Removed Columns"

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Anonymous
Not applicable

Hi, 

 

I was searching for the DAX on your problem when I discovered this past thread, which is highly relevant to yours. 

 

https://community.powerbi.com/t5/Desktop/Count-no-of-comma-occurrences-in-a-column/td-p/79183

 

multiple ways to do it - eg You can delimit the column, but I would create a copy and find DAX to count the number of times a comma occurs.

 

Sorry I couldn't give a specific query to your issue!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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