Forum Discussion
String Count with loop in each row
- 3 years ago
Hi dannytan1112
Please refer to attached sample file with the solutionCount = VAR CurrentElelent = SELECTEDVALUE ( Elements[Element] ) RETURN SUMX ( VALUES ( 'Table'[Column Name] ), VAR String = 'Table'[Column Name] VAR Items = SUBSTITUTE ( String, ", ", "|" ) VAR Length = PATHLENGTH ( Items ) VAR T1 = GENERATESERIES ( 1, Length, 1 ) VAR T2 = SELECTCOLUMNS ( T1, "@Item", PATHITEM ( Items, [Value] ) ) VAR T3 = FILTER ( T2, CONTAINSSTRING ( [@Item], CurrentElelent ) ) RETURN COUNTROWS ( T3 ) )
Hi tamerj1
The 2nd Table is StoredProcedureresult that changes when parameters are changed
| season | MOTcode | MOTname | countryofproduction | planningmarketcode | productionGroupId | ProductionTypeCode | InshopWeek | PeriodNum | Division | percentageVal | LLT | InshopWeek - Copy | ISW-Year | ISW-Week | TOD | TODMonth |
| 7 | 1 | Sea | IN | 1026 | 10 | 63 | 202350 | 0 | 103 | 0.562 | 6 | 202350 | 2023 | 50 | 202344 | 2023-10 |
| 7 | 1 | Sea | IN | 1011 | 10 | 63 | 202350 | 0 | 103 | 0.446 | 8 | 202350 | 2023 | 50 | 202342 | 2023-10 |
| 7 | 1 | Sea | IN | 1006 | 10 | 63 | 202350 | 0 | 103 | 0.414 | 7 | 202350 | 2023 | 50 | 202343 | 2023-10 |
| 7 | 1 | Sea | ID | 1011 | 10 | 63 | 202351 | 0 | 103 | 1.296 | 9 | 202351 | 2023 | 51 | 202342 | 2023-10 |
| 7 | 1 | Sea | MM | 1026 | 10 | 63 | 202349 | 0 | 103 | 6.726 | 7 | 202349 | 2023 | 49 | 202342 | 2023-10 |
Hi tamerj1 I have sent the Two table data, Here the tables are filtered based on ProductionTypecode and PeriodNum from both tables, after filtering each row from PlanDetails has a UniqueKey row, This should result in a table where each UniqueKey row from "PlanDetails" is duplicated with all the data from "Bought Details" and combined with the filtered data from "StoredprocedureResult" for each row based on the specified conditions(from Stored Procedure, the columns we need from SP result are MOTcode MOTname planningmarketcode InshopWeek percentageVal LLT InshopWeek - Copy ISW-Year ISW-Week TOD TODMonth)