I spent 18 days in Norway last summer, travelling in planes, trains, busses, ferries, and ships (Hurtigruten). I did done some very scenic trains trips and cruising through fjords, before I arrived in Bergen, at the tail end of my trip. But, I still found my day trip from Bergen to Flam very beautiful and enjoyable.
The train trip from Bergen to Myrdal was very nice. The train from Myrdal to Flam was even better. As PsiFighter37 mentioned, Flam is very small and not much to do. From Flam I took a sightseeing boat to Gudvangen. The cruise through the Sognefjord was very beautiful. I then took a bus from Gudvangen to Voss, which was also spectacular. I then took the train from Voss back to Bergen.
The entire trip was wonderful, so I would definitely encourage you to visit Flam, but don’t comeback from Flam to Myrdal by train. Do the boat cruise on the Sognefjord. Alternately, you can take a boat from Flam back to Bergen (
https://www.norled.no/en/fjordcruise...rgen-to-flaam/)