I have a use case where I need to concatenate values from merged cell with other columns based on condition
| Name | Frequency | Old Measure | New Measure | What's needed |
|---|---|---|---|---|
| Name1 | Freq1 | Mea1 | Name1-Freq1-Mea1 | |
| Freq2 | Nmea1 | Name1-Freq2-Nmea1 | ||
| Freq3 | Mea2 | Name1-Freq3-Mea2 | ||
| Name2 | Freq4 | Mea3 | Name2-Freq4-Mea3 | |
| Freq5 | Nmea2 | Name2-Freq5-Nmea2 | ||
| Name3 | Freq6 | Mea4 | Name3-Freq6-Mea4 | |
| Name4 | Freq7 | Nmea3 | Name4-Freq7-Nmea3 | |
| Name5 | Freq8 | Nmea4 | Name5-Freq8-Nmea4 | |
| Freq9 | Nmea5 | Name5-Freq9-Nmea5 | ||
The formula should check for column Old Measure and New Measure which ever is filled should concatenate with Name and Frequency.
I did try to take the answer from this similar question - 
Explanation
This part
lookup(row(A2:A),row(A2:A)/(A2:A<>""),A2:A)
Fills the gaps in A2:A with the last non-empty value above.
Then
byrow(...,lambda(r,textjoin("-",1,r)))
Concatenates row-by-row the values from the previous array and the values in B2:D.
And finally
query(...,"limit "&-1 max(if(B2:D<>"",row(B2:D)))
Constrains the resulting array to the last filled row.
