Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
In my recent quest to create or catalog as many DAX equivalents for Excel functions, this one is a bit brute force but I think I got all of the scenarios.
IMAGINARY =
VAR __Complex = [COMPLEX]
RETURN
SWITCH(TRUE(),
__Complex = "i" || __Complex = "j",1, // handle i
__Complex = "-i" || __Complex = "-j",-1, // handle -i
FIND("i",__Complex,,-1) = -1 && FIND("j",__Complex,,-1) = -1,0, // handle only real numbers
FIND("+",__Complex,,-1) <> -1 && LEN(__Complex) - FIND("+",__Complex,,-1) = 2,1,
FIND("+",__Complex,,-1) <> -1,MID(__Complex,FIND("+",__Complex)+1,LEN(__Complex) - 1 - FIND("+",__Complex)) + 0, // handle positive i
FIND("-",__Complex,2,-1) <> -1,MID(__Complex,FIND("-",__Complex,2)+1,LEN(__Complex) - 1 - FIND("-",__Complex,2)) * -1, // handle both negative real and negative i
MID(__Complex,FIND("-",__Complex)+1,LEN(__Complex) - 1 - FIND("-",__Complex)) * -1 // handle just negative i
)
eyJrIjoiZTRhNDdlZmEtZGI1ZC00YTQ3LWFlNTYtYjUwY2UyZWZlNTU5IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9