Forum Discussion
Find the text from string and remove remain part
Hi all,
I would like to create a new column in a table that will show me number of Master Document for Project Copies.
Example:
Table "Document"
| Document Number | Document Category |
| 61-2300-P-5090 | Master Document |
| 61-2300-P-5090-07812 | Project Working Copy |
| 61-2300-P-5090-05908P | Project Working Copy |
| 61-2300-P-5090-05908T1 | Project Working Copy |
| 61-2300-P-5090-05908T | Project Working Copy |
| 61-2300-P-5090-07812-21 | Project Working Copy |
Desired New Column that will identify us the Number of Master Document of this copies:
| Document Number | Document Category | New column (Master Documents) |
| 61-2300-P-5090 | Master Document | 61-2300-P-5090 |
| 61-2300-P-5090-07812 | Project Working Copy | 61-2300-P-5090 |
| 61-2300-P-5090-05908P | Project Working Copy | 61-2300-P-5090 |
| 61-2300-P-5090-05908T1 | Project Working Copy | 61-2300-P-5090 |
| 61-2300-P-5090-05908T | Project Working Copy | 61-2300-P-5090 |
| 61-2300-P-5090-07812-21 | Project Working Copy | 61-2300-P-5090 |
One more thing is the lenght of Master Documents can be different and we need to check it by Category.
I tried this code, but it does not work correctly:
I am not sure it will work with your big dataset, but you can try the following in Power Query:
1) Sort your table by "Document Number".
2) Add a conditional column.
3) Apply "Fill Down" form the newly created column.
Best Regards,
Alexander
5 Replies
- barritown
Solution Sage
Hi Nurzh,
Please try this calculated column versus your data:
And in plain text for convenience:
Document Master = VAR CurrentNumber = [Document Number] RETURN MINX ( FILTER ( ADDCOLUMNS ( FILTER ( ALL ( Document ), Document[Document Category] = "Master Document" ), "Match", VAR CurrentMaster = [Document Number] RETURN CONTAINSSTRING ( CurrentNumber, CurrentMaster ) ), [Match] = TRUE () ), [Document Number] )Best Regards,
Alexander
- barritown
Solution Sage
Hi Nurzh,
I knew my solution is greedy in terms of resources, but 6-7 hours - wow.
I will think how to opimize my [DAX] solution - not sure that I will be able to turn hours into minutes, but I'll try. Before that, could you please clarify how many "master" entries you have among those 2.8 million rows?
As for the Power Query solution, maybe it is worth duplicating this post in the "Power Query" section of this forum - I guess Power Query gurus live there. 🙂
Best Regards,
Alexander