cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Cunial
New Member

Is it possible to split rows

 

Hi All,

 

I am trying to split a row into several rows with only the value ("Indicator" below) changing.

 

Here's an example of what I am attempting.

 

 Example:  
IDNameItemIndicator
1JohnOranges30
    
 Result:  
ID:NameItemIndicator
1JohnOranges15
2JohnOranges15

 

I am trying to apply the logic; for all 'John' rows create a new row but divide indicator by x, in this case it is 2. 

 

I am new to PowerBI and after attempting to do this in DAX and M I am unsure about a couple things:

1. Is DAX or M the correct place to apply this change

2. Is this change possible

 

Also I would greatly appreciate any guidance for how I might do this if it is possible. 

 

Thanks in advance,

1 ACCEPTED SOLUTION

You can do it in Power Query as illustrated in the video and resulting in the query code below.

 

Basically Power Query takes care of the steps to have your data properly structured into the datamodel, after which DAX takes over for further modeling and adding measures.

 

So in my view this should be done in Power Query, but I must admit I'm pretty biased towards Power Query.

Many people out here would prefer DAX.

 

 

The query code that was generated during video recording:

 

let
    Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "Custom", (ThisRow) => if ThisRow[Name] = "John" then List.Transform({1..Parameter_x},each ThisRow[Indicator]/Parameter_x) else {ThisRow[Indicator]}, type {number}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Indicator"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Indicator"}})
in
    #"Renamed Columns"
Specializing in Power Query Formula Language (M)

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Cunial,

 

I am not sure this is the best way, but how it is possible is:

 

Create a table where you duplicate those 3 columns (name, item, indicator)

 

After you created a new table with the desired columns, add a calculated column where you divide indicator by 2.

 

information about creating new columns can be found here :

https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-calculated-tables/

 

Please let me know if this worked for you,

 

L.Meijdam

You can do it in Power Query as illustrated in the video and resulting in the query code below.

 

Basically Power Query takes care of the steps to have your data properly structured into the datamodel, after which DAX takes over for further modeling and adding measures.

 

So in my view this should be done in Power Query, but I must admit I'm pretty biased towards Power Query.

Many people out here would prefer DAX.

 

 

The query code that was generated during video recording:

 

let
    Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "Custom", (ThisRow) => if ThisRow[Name] = "John" then List.Transform({1..Parameter_x},each ThisRow[Indicator]/Parameter_x) else {ThisRow[Indicator]}, type {number}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Custom",{"Indicator"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Indicator"}})
in
    #"Renamed Columns"
Specializing in Power Query Formula Language (M)

I have a similar question is it possible to split the rows based on the value in the indicator. Like John - 30 this row should split into 30 rows

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors