Tricky CSV file creation or RG/Text Box display data

I need to be able to generate a csv/txt file that looks like the below. The tricky part is that there are three types of rows.

  1. B row only exists at the top of the file and only has a few data fields.
  2. Then there is an H and at least one D row for every “user” that we have. There is a User ID (the one that starts with “UHS”) so we can use that ID in this requirement to sort by the User ID and then by the Row Type (excluding the B row so it stays at the top by itself).
  3. The H and D rows have different types of data and different quantities of data.
  4. This report will be generated monthly with different data each month, but same format. Will use a date field to make sure we are only pulling data for a certain time period.

We have tried to figure a way to just display data in an RG or a Text box, but haven’t been successful with that either. We figure if we could do one of these options, then we could probably get that converted to a CSV/Txt file.

Not sure how to make this work. Any creative thinkers out there that know how I can do this?