cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rjcarpen
Level: Powered On

Parsing and re-structuring data table

I have a SQL sourced dataset with the following format that needs to be parced, re-structured, and have duplicates removed.  I don't have access to change the SQL server, and I would prefer to keep this in PowerApps instead of setting up a flow.

 

Problem: "Heat No": output is being stored as a column of tables instead of a column of values.  This is also getting pretty messy and I keep wondering if there is a more elegent way (such as ForAll?) to do this transformation.


Incoming Format:

DescriptionPlannerJob
** HEAT NUMBER 1235 **A3 
** HEAT NUMBER 1236 ** CCP **B5 
** HEAT NUMBER 1237 **B7 
** HEAT NUMBER 1237 **B9 

 

Target Format:

Heat NumberPlanner
1235A
1236B
1237B

 

Current Code:

//Copy SQL to buffer
ClearCollect(DataImport_JobListBuffer,'[MFGHEAT].[WIPDATA]');  //Tried to filter this directly without success.  Seems you need to buffer data in

//Filter buffer
ClearCollect(DataImport_HeatList,Filter(DataImport_JobListBuffer,'A$Organization_Code'="NWT",ITEM_PLANNER_CODE<>"NWT3"));

//Parse out heat number
ClearCollect(DataImport_HeatList2,Substitute(DataImport_HeatList.Description,"**HEAT NUMBER",""));
ClearCollect(DataImport_HeatList2,Substitute(DataImport_HeatList2.Description,"**CPP**",""));
ClearCollect(DataImport_HeatList2,Substitute(DataImport_HeatList2.Description,"**CRP**",""));
ClearCollect(DataImport_HeatList2,Substitute(DataImport_HeatList2.Description,"**",""));

//Add columns back in
ClearCollect(DataImport_HeatList3,AddColumns(DataImport_HeatList,"Heat No",DataImport_HeatList2.Description));

//Remove duplicates
//ClearCollect(DataImport_HeatList4,Distinct(DataImport_HeatList3,Heat No));
1 ACCEPTED SOLUTION

Accepted Solutions
hnguy71
Level 8

Re: Parsing and re-structuring data table

I did a quick test on my side and here's what I came up with:

 

ClearCollect(
    DataImport_JobListBuffer,
    '[MFGHEAT].[WIPDATA]'
);
Distinct(
    ClearCollect(
        _DataImport_HeatList,
        AddColumns(
            Filter(
                DataImport_JobListBuffer,
                'A$Organization_Code' = "NWT",
                ITEM_PLANNER_CODE <> "NWT3"
            ),
            "Heat Number",
            Concat(
                Filter(
                    Split(
                        Description,
                        ""
                    ),
                    IsMatch(
                        Result,
                        "^[0-9]*"
                    )
                ),
                Result
            )
        )
    ),
    'Heat Number'
)


which gave me this:
remove letters and special.png

View solution in original post

4 REPLIES 4
hnguy71
Level 8

Re: Parsing and re-structuring data table

I did a quick test on my side and here's what I came up with:

 

ClearCollect(
    DataImport_JobListBuffer,
    '[MFGHEAT].[WIPDATA]'
);
Distinct(
    ClearCollect(
        _DataImport_HeatList,
        AddColumns(
            Filter(
                DataImport_JobListBuffer,
                'A$Organization_Code' = "NWT",
                ITEM_PLANNER_CODE <> "NWT3"
            ),
            "Heat Number",
            Concat(
                Filter(
                    Split(
                        Description,
                        ""
                    ),
                    IsMatch(
                        Result,
                        "^[0-9]*"
                    )
                ),
                Result
            )
        )
    ),
    'Heat Number'
)


which gave me this:
remove letters and special.png

View solution in original post

Super User
Super User

Re: Parsing and re-structuring data table

@Rjcarpen 

In addition to @hnguy71 's suggestion, you can also look at applying GroupBy to achieve these same results.

 

I'm not entirely sure from your sample data if the Planner is unique as well. In other words - if there was a ** HEAT NUMBER 1237 ** with Planner A possibility or not.

So, if the above is not true, then you can consider this formula for your testing (I assume you want this in a collection for some reason, so I will construct with one):

ClearCollect(HeatList, 
   DropColumns(
      GroupBy(
            AddColumns(
                Filter('[MFGHEAT].[WIPDATA]', 
                         'A$Organization_Code' = "NWT" &&
                         ITEM_PLANNER_CODE <> "NWT3"
                        ),
                "HeatNumber",  Match(Description, MultipleDigits).FullMatch
                ),
       "HeatNumber",
       "Planner",
       "Records"
       ),
   "Records"
   )
)

Based on your supplied data, this produces a collection called HeatList with three records -

HeatNumber    Planner

    1235                 A

    1236                 B

    1237                 B

 

I hope that is clear and helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Highlighted
Rjcarpen
Level: Powered On

Re: Parsing and re-structuring data table

Thanks @RandyHayes , this worked well too and is a pretty elegent solution.  I am going to have to find a way to manipulate my downstream app to move in this direction.

Rjcarpen
Level: Powered On

Re: Parsing and re-structuring data table

Thanks @hnguy71 , this worked well and gets me going!

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Demo Extravaganza Championship Voting Open

Voting Ends: October 30, 2019!

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 450 members 5,405 guests
Please welcome our newest community members: