Image Analysis in Power BI – Using AI Vision Insights [3/4]
Published Jul 19 2022 12:40 PM 732 Views
Microsoft

Step C: Creating Measures to change UI behaviour

In the Power Query screen

  1. Create a new table called, “_GUI Measures” with a Blank Query. This will be a dummy table, so that we can group our measures in one place.
  2. Click Close and Apply to close the Power Query window.

In the Power BI Desktop screen

  1. Change the data classification of the ImageURL column to Image URL
  2. Change the data classification of the WebURL column to Web URL
  3. Set default summarization of Images.ImageId to Maximize. 
  4. Ensure there is a bi-directional relationship between the two tables on ImageId 

Picture22.png

      7. Create a new Measure called Tag Measure under “_GUI_Measures” 

 

 

 

 

Tag Measure = IF( 
//Is the Tag Column filtered? 
// True in Matrix Visual when row is expanded, and False when row is collapsed.
ISFILTERED( ImageTags_VisionInsight[Tag])

,//value to show in Expanded (detail) Mode in Matrix Visual when there is a Tag Value 
MAX(ImageTags_VisionInsight[Tag]) //Detail   

,//value to show in Collapsed (Summary) Mode 
   //simple comment and uncomment one of the following for desired behaviour.

    //Show Single Tag value associated to the MAX Confidence for the ImageId
    CALCULATE(MAX(ImageTags_VisionInsight[Tag]), FILTER(ImageTags_VisionInsight, ImageTags_VisionInsight[Confidence] = MAX(ImageTags_VisionInsight[Confidence]) ))
   
    //Show All Tag values comma-separated associated to the MAX Confidence 
    //MAX(ImageTags_VisionInsight[Tags] ) //Summary comma seperated Tag Values for SubTotal
)
​

 

 

 

 

Formula Explanation: The ISFILTERED function is used to determine if the Tag column is being filtered directly.

When the matrix visual is expanded state then the Tag column has values and has a filter context so the function will return TRUE, but when the matrix visual is in collapsed state there is no filter context being applied on the Tag column so the function will return FALSE.

When the matrix visual is in expanded state then we want to display the Tag value, since this is a measure will use the MAX() aggregate. This will basically do a MAX of a single row, which is return the same value as the column value.

When the row in the matrix visual is in collapsed state then we have two options of how we want to display the value: 

  1. Display all tag values comma-separated. Which means, it makes more sense to not display value in the confidence cell.

//MAX(ImageTags_VisionInsight[Tags])

Since this is a measure, we are using MAX. If you want this behaviour, then uncomment this line and then comment out the CALCULATE line.

OR

    b. Display the maximum confidence, and then display the Tag corresponding to the maximum confidence.

There is a relationship between the Images table and the ImageTags_VisionInsight table on the ImageId column. Using the CALCULATE function we can retrieve the Tag value by filtering confidence value to match the MAX confidence value for that ImageId.  

 

 8. Create a new Measure called Confidence Measure under “_GUI_Measures”. 

 

 

 

 

Confidence Measure = /*This uses the SWITCH instead of Nested IF statements*/
SWITCH(TRUE()

//If Tag is filtered, then it is a single Tag Value in Expanded Mode, so return the Confidence value.
,ISFILTERED( ImageTags_VisionInsight[Tag])
,MAX(ImageTags_VisionInsight[Confidence]) 

//If Tag Measure has comma-separated value then we are in Collapse Mode, so return blank. 
,CONTAINSSTRING([Tag Measure],",")
,BLANK()

//If Tag Measure is blank return blank. 
,ISBLANK([Tag Measure]) 
,BLANK()

, //else this means we are showing a Single tag in Expanded Detail Mode, So simple return Confidence % 
MAX(ImageTags_VisionInsight[Confidence]) 
)

 

 

 

 

 9. Set the Folder location and Percentage format for the Confidence MeasureFolder_location.png

 

10. Similarly set the folder for the Tag Measure to Visual Insights.

 

Summary 

We created DAX measures to control what is displayed as the Tag and the Confidence Value when a row is in collapsed (summarized) mode in a Matrix Visual.  In the next post we will use these measures in the Matrix Visual.  

Version history
Last update:
‎Jul 19 2022 12:36 PM
Updated by: