Greg_Deckler's avatar
Greg_Deckler
Icon for Community Champion rankCommunity Champion
6 years ago

IMREAL

In my recent quest to create or catalog as many DAX equivalents for Excel functions, this one is analogous to IMAGINARY.

 

IMREAL = 
    VAR __Complex = [COMPLEX]
RETURN
    SWITCH(TRUE(),
        __Complex = "i" || __Complex = "j" || __Complex = "-i" || __Complex = "-j",0, // handle i/j -i/-j
        FIND("i",__Complex,,-1) = -1 && FIND("j",__Complex,,-1) = -1,__Complex + 0, // handle only real numbers
        FIND("+",__Complex,,-1) <> -1,LEFT(__Complex,FIND("+",__Complex)-1) + 0, // handle positive i
        FIND("-",__Complex,2,-1) <> -1,LEFT(__Complex,FIND("-",__Complex,2)-1) + 0, // handle both negative real and negative i
        0 // handle just negative i
    )

This seems like a very self affirmational function name...

 

 

No RepliesBe the first to reply