Forum Discussion
Nested IF statement?
I split the code in two conditions :
- If there is only one filter applied and there is a matching image in the table, display the image.
- If there is no filter applied or no matching image in the table, display a placeholder image.
Image =
VAR img =
IF (
HASONEVALUE ( 'City Images JPG Base 64'[Name] ),
"data:image/jpg;base64, "
& CONCATENATEX (
'City Images JPG Base 64',
'City Images JPG Base 64'[Pic],
"",
'City Images JPG Base 64'[Index], ASC
),
IF (
COUNTROWS ( 'City Images JPG Base 64' ) = 0
|| ISBLANK ( 'City Images JPG Base 64'[Pic] ),
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8v5+jwAHuwM+g5t5ewAAAABJRU5ErkJggg==",
"data:image/jpg;base64, "
& CONCATENATEX (
'City Images JPG Base 64',
'City Images JPG Base 64'[Pic],
"",
'City Images JPG Base 64'[Index], ASC
)
)
)
RETURN
img
NB : I used base64-encoded PNG image as the placeholder. You can replace it with your own placeholder image in the same format as your other images.
- bonjourposte3 years agoHelper V
Thanks, Amira! I think my base64 code is around 90,000 characters, though. Is it still appropriate to put it in this function?
- AmiraBedh3 years agoSuper User
It is possible but the recommendation is to use smaller Base64 codes in DAX functions whenever possible
- bonjourposte3 years agoHelper V
Hi, I tried your code, but instead of the 90,000 characters of Base 64, I just wrote the name of the picture in the folder. It didn't like that- how would you reference the image if not by the code or the title?
Image =var img =IF(HASONEVALUE('City Images JPG Base 64'[Name]),"data:image/jpg;base64, " &CONCATENATEX('City Images JPG Base 64','City Images JPG Base 64'[Pic],"","data: image/jpg;base64, " &'City Images JPG Base 64'[INDEX],ASC),IF(COUNTROWS('City Images JPG Base 64')=0|| ISBLANK('City Images JPG Base 64'[Pic]),"data: image/jpg;base64,AA Canada generic","data: image/jpg;base64, " &CONCATENATEX('City Images JPG Base 64','City Images JPG Base 64'[Pic],"",'City Images JPG Base 64'[INDEX],ASC)))RETURN img