Dynamic measurement selection to display as a secondary line in chart

Hi everybody!
I need to dynamically display or hide the second line in the chart, depending on selected dimension
There is a flat table structure i.e.

time | kpi1 | kpi2 | kpi3 | ...

For kpi1, we need to display a single line on the chart, but for kpi2 and kpi3 we need to have them both charted simultaneously.
Currently, I did a workaround with an expression on colors stack which looks as follows:

sum(CASE
    WHEN <<kpi>> = kpi2 THEN [kpi3]
    ELSE 0 
END)

In this case, I have a line on zero level. Now I need to remove it. The expression works without aggregation (sum), that indicates that the visual can handle null values, but if I do aggregation it fails with
infinity/null measures or non numeric aggregates

I also tried to transpose the table, to have a single measure in each row and the name of a related measure. Stuck with the same null handling problem though.

Does anybody know the way to dynamically display the second line?