such string-operations are always ugly and it's nearly impossible all possible combinations to query. I think you need the same transformations for Dateiname within the mid-function to avoid confusion:
MID(INDEX(REPLACE(UPPER(Dateiname), ' ', '_'), 'N', 2), INDEX(REPLACE(UPPER(Dateiname), ' ', '_'), 'N', 2), 4)
Maybe you could also use subfield(Dateiname, '_', 3) to simplify your expression.
I agree, that would be much easier - but they sometimes introduce one more BLANK, so I cannot simply use Subfield() - I have to work with INDEX().
I think I have now made it - though I still don't know why, after I had already replaced the BLANKs, QlikView still didn't "see" an underscore, but a BLANK - I'll have another look.
not quite clear, what you actually try to extract:
Looking at the filename it seem to be:
Schichtplan_NTB1_Ivan KW33 Früh
"Schichtplan_" + Plant + "_" + Name + Week(start with KW) + Shift
If your only problem are blanks, they can be neglected and you may work with a combination of stringformulas to find the individual parameters
Formulas in the example will work also in a script.
FileName.qvw 152.2 K