Skip to main content
ankitt714102
March 30, 2023
Question

Repeat row data based on countcolumn

  • March 30, 2023
  • 4 replies
  • 0 views

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
March 30, 2023

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

ankitt714102
March 31, 2023

Thanks Stefan.

March 30, 2023

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
March 31, 2023

Thanks sanchit.