Concatenate with line breaks in dataview tables

I am trying to use dataview to make a table to combines several fields into a single column, and displays multiple entries for a given file with a linebreak between them.

The application here is a media journal. For instance, I use the following code:

table TvLog + MusicLog + ReadingLog as "media" 
where TvLog + MusicLog + ReadingLog != null 
sort desc

In the case of a Daily Note with both a TvLog and MusicLog entry, the query results in an entry like this:

Date | TvLogEntryMusicLogEntry

What I want is an entry like this:

Date | TvLogEntry
     | MusicLogEntry

Things I have tried

I have a workable but non-ideal solution. I manually coded in line breaks between the fields like so:

table TvLog + "<br>" + MusicLog + "<br>" + ReadingLog as "media" 

This works, but null values give me a headache because a day with just a MusicLog entry reads as:

 Date | -
      | MusicLogEntry
      | -

Changing the settings for Dataview to render null as nothing only helps marginally, because the manual breaks are in there, so the dashes disappear but the empty space remains.

I can live with this if I must, but it’s irking me because there has to be a better way, right?!

1 Like

You could try using the choice(...) function around each of your fields in the first line; if the field is not null, field + “\n”, otherwise output “”.

Also is your WHERE statement trying to check if TvLog != null OR MusicLog != null OR ReadingLog != null? I am surprised the concatenation you have is working - do you know why it is allowing you to add nulls? Always appreciate the opportunity to learn new software concepts!

Terrific! This appears to work! A little messy, and I suspect that there is maybe a cleaner solution to this whole problem that involves approaching it differently, but I’m happy enough to have it work.

As for the nulls, tbh I’m not sure why it’s working. I just tried and it seemed to work, but it’s possible that I just don’t have enough data in my testcase to demonstrate how it’s actually broken.

I’ll probably be swapping it out for the expression you mentioned to try and ensure no weird bugs crop up later!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.