How to replace blank rows using logic app?

Vivek Komarla Bhaskar 911 Reputation points
2023-07-10T15:22:33.64+00:00

Hi,

I have a logic app that does quite a bit and eventually creates a CSV output and a blob from the CSV output. Having trouble fixing a problem with my CSV output content. The problem is that there are blank rows in every alternate record. Is there a way to remove all the empty rows? I tried all the below but nothing worked -

replace('body('Create_CSV_table)','
','')
replace('body('Create_CSV_table)',variables('Blankline'),'') ----(Create a variable Blankline with carriagereturn as value)

:::::::::::::::Sample Data:::::::::::::::
SectionID,SectionTitle 
586304181,Content Type  

586304622,Article  

586305066,Live Blog  

586688191,Non Content  

586305100,Event  

586305124,Q&A  

586304663,Clips

:::::::::::::::Expected output:::::::::::::::
SectionID,SectionTitle
586304181,Content Type
586304622,Article
586305066,Live Blog
586688191,Non Content
586305100,Event
586305124,Q&A
586304663,Clips
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,996 questions
{count} votes

Accepted answer
  1. Sonny Gillissen 3,351 Reputation points
    2023-07-11T18:19:36.7+00:00

    Hi Vivek Komarla Bhaskar

    Thank you for reaching out on Microsoft Q&A!

    I've tested your outputs in my test lab and came to a very simple but straightforward solution to your problem. The empty lines are recognised bij a double return, whereas the "normal" lines only have one return (before content starts again).

    Therefor I think the solution would be to:

    • Define a string variable called 'doubleReturn' and enter two returns in it
      Screenshot 2023-07-11 at 20.17.46
    • Define a string variable called 'singleReturn' and enter one return in it
      Screenshot 2023-07-11 at 20.17.52
    • Replace all double returns in your CSV output with a single return using the following code:
      replace(body('Create_CSV_table'),variables('doubleReturn'),variables('singleReturn'))

    Please note that even though this solution may solve your issue with the blank lines, it's better to check why the source of this action is returning empty values in the first place. It would be possible to use a 'Filter' action and leave only lines with content in it, before inputting it to the 'Create CSV table' action.

    Please click “Accept answer” if you find this helpful. Feel free to drop additional queries in the comments below!

    Kind regards,

    Sonny

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful