Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
mark_endicott
Helper II
Helper II

DAX to test if an Image is returned from URL

Hello, 

 

I am using DAX to construct an Image URL based on selections the user makes in a dashboard. Does anyone know if there is a way of testing if the image exists through DAX? So that if an image does not exist, I can default to another URL.

 

I have tried wrapping an IF ( ISBLANK ( )) around the return of the URL - but ofcourse this is assessing the URL which wont be blank. 

 

Please see below for the full DAX.

 

 

VAR CDN_domain = "anon_domain_name"
VAR current_territory =
    LOWER ( SELECTEDVALUE ( 'TERRITORY'[ISO Currency code] ) )
VAR current_value =
    SELECTEDVALUE ( PRODUCT_ATTRIBUTES[value] )
VAR sas_key =
    CALCULATE (
        SELECTEDVALUE ( 'rls keys'[keyvalue] ),
        KEEPFILTERS (
            FILTER (
                ALL ( 'rls keys'[keyname], 'rls keys'[environment] ),
                'rls keys'[keyname] = "SAS key for images"
                    && 'rls keys'[environment] = "Prod"
            )
        )
    )
VAR full_string = CDN_domain & current_territory & "/" & current_value & ".jpg" & sas_key
RETURN
    IF (
        ISBLANK ( full_string ),
        CDN_domain & "gbr" & "/" & current_value & ".jpg" & sas_key,
        full_string
    )

 

1 ACCEPTED SOLUTION

Hi @mark_endicott ,

 

I'm sorry to say that in DAX, isblank is the most appropriate function to use to determine if a value exists. If you are involved in fewer URLs, perhaps you could write something separately like :

 

If(selecvalue(your url)= true url,"have image","no image")

 

 

Through this to check if your url is right, because right url can return image, so this way is equivalent to an indirect determination, but is more suitable for cases with less data.

For more information about DAX you can refer this link:DAX function reference - DAX | Microsoft Docs

 

Best regards,

Community Support Team Selina zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
v-mengzhu-msft
Community Support
Community Support

Hi @mark_endicott ,

 

Based on my understanding of the concept of the DAX function, I don't actually think you can use it to determine the presence of an image.

vmengzhumsft_0-1661740033039.png

As the documentation says, it is a calculation of the data, so you can determine whether the URL exists, as you say, but not directly whether it can return the image.

 

This is my understanding, please let me know if there is any misunderstanding.

 

Best regards,

Community Support Team Selina zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-mengzhu-msft - So as I am creating the URL with my DAX, is there any way you can think of other than ISBLANK() to qualify if the URL truely exists?

Hi @mark_endicott ,

 

I'm sorry to say that in DAX, isblank is the most appropriate function to use to determine if a value exists. If you are involved in fewer URLs, perhaps you could write something separately like :

 

If(selecvalue(your url)= true url,"have image","no image")

 

 

Through this to check if your url is right, because right url can return image, so this way is equivalent to an indirect determination, but is more suitable for cases with less data.

For more information about DAX you can refer this link:DAX function reference - DAX | Microsoft Docs

 

Best regards,

Community Support Team Selina zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.