cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Fredrik_V
New Member

Multiple column split into rows

Looking for a way to split multiple columns into rows.

Example input collection looks like this:

PowerBi1.JPG

 

And output collection should be:

PowerBi2.JPG

 

Anyone knows if its possible?

And if doable handle if value is missing (missing values zero or null)

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@Fredrik_V 

Sure thing.

Consider the following formula:

ClearCollect(colFredrik,
    {Title:"Case1", Status:"yes,no", Active:"yes,no", Week:"1,2"},
    {Title:"Case2", Status:"yes,yes,yes,yes,no,no", Active:"yes,yes,yes,yes,yes,yes,yes", Week:"38,39,40,41,42,43"}
);

Clear(colFredrik2);

ForAll(colFredrik,
    With({statuses:Split(Status, ","), actives:Split(Active, ","), weeks:Split(Week, ",")},
        With({statCount:CountRows(statuses), activeCount:CountRows(actives), weeksCount:CountRows(weeks)},

            ForAll(Sequence(Max(statCount, activeCount, weeksCount)),
                Collect(colFredrik2,
                    {Title: Title,
                     V: Text(Value) & "/" & Text(statCount),
                     Status: If(Value>statCount, "", Last(FirstN(statuses, Value)).Result),
                     Active: If(Value>activeCount, "", Last(FirstN(actives, Value)).Result),
                     Week: If(Value>weeksCount, 0, Value(Last(FirstN(weeks, Value)).Result))
                    }
                )
            )
        )
    )
)

 

You'll notice that I also added an extra "yes" to the second Active record.  This will produce a blank for Status and a 0 for Week.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
RandyHayes
Super User III
Super User III

@Fredrik_V 

Sure thing.

Consider the following formula:

ClearCollect(colFredrik,
    {Title:"Case1", Status:"yes,no", Active:"yes,no", Week:"1,2"},
    {Title:"Case2", Status:"yes,yes,yes,yes,no,no", Active:"yes,yes,yes,yes,yes,yes,yes", Week:"38,39,40,41,42,43"}
);

Clear(colFredrik2);

ForAll(colFredrik,
    With({statuses:Split(Status, ","), actives:Split(Active, ","), weeks:Split(Week, ",")},
        With({statCount:CountRows(statuses), activeCount:CountRows(actives), weeksCount:CountRows(weeks)},

            ForAll(Sequence(Max(statCount, activeCount, weeksCount)),
                Collect(colFredrik2,
                    {Title: Title,
                     V: Text(Value) & "/" & Text(statCount),
                     Status: If(Value>statCount, "", Last(FirstN(statuses, Value)).Result),
                     Active: If(Value>activeCount, "", Last(FirstN(actives, Value)).Result),
                     Week: If(Value>weeksCount, 0, Value(Last(FirstN(weeks, Value)).Result))
                    }
                )
            )
        )
    )
)

 

You'll notice that I also added an extra "yes" to the second Active record.  This will produce a blank for Status and a 0 for Week.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Works great, thank you

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,268)