Skip to main content
ankitt714102
Known Participant
Mar 30, 2023 5:53 PM UTC
Question

Repeat row data based on countcolumn

Hi Expert,

I have made a expression rule which is returning datasubset .

For eg: This is my query entity returning data.

Col A   Col B   Countcolumn

a         b               2

d         e               3

g         h               1              

Now i want to repeat row based on count column.How can i achieve following output:

Col A  Col B

a          b

a          b

d          e

d          e

d          e

g          h

Please help.

4 replies

stefanhelzle0001
Brainy
Mar 30, 2023 5:56 PM UTC

Two nested foreach loop should do that. The outer one on the rows, and the inner one on that count column.

ankitt714102
Known Participant
Mar 31, 2023 2:47 AM UTC

Thanks Stefan.

sanchitg0002
Inspiring
Mar 30, 2023 6:54 PM UTC

Like Stefan mentioned, nested forEach will do the trick 

a!localVariables(
  local!data: {
    { col1: "A", col2: "B", count: 4 },
    { col1: "C", col2: "D", count: 2 }
  },
  a!flatten(
    a!forEach(
      items: local!data,
      expression: a!localVariables(
        local!col1: fv!item.col1,
        local!col2: fv!item.col2,
        local!count: fv!item.count,
        a!forEach(
          items: enumerate(local!count),
          expression: { col1: local!col1, col2: local!col2 }
        )
      )
    )
  )
)

ankitt714102
Known Participant
Mar 31, 2023 2:48 AM UTC

Thanks sanchit.