Forum Discussion

arlequin71's avatar
arlequin71
Helper II
3 years ago
Solved

Percentage Difference by selecting reference from slicer

Hi, appreciate if anyone can help me on this.

I'm using a quick meassure "Percentage difference from filtered value" for displaying a visual like attached one.   It works as expected but i require to make it dynamic, by selecting the reference from a slicer so product prices percentage difference are indexed to selected product and not to fixed defined product like this :

 
Avg Price % difference from Product A =
VAR __BASELINE_VALUE = CALCULATE([Avg Price], 'Table1'[Product Name] IN { "Product A" })
VAR __MEASURE_VALUE = [Avg Price]
RETURN
    IF(
        NOT ISBLANK(__MEASURE_VALUE),
        DIVIDE(__MEASURE_VALUE - __BASELINE_VALUE, __BASELINE_VALUE)
    )

 

 

This is my main table:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hdQxD4IwEAXgv2I6Q0JbasuIwOLkThiMjkYNkf+vdwwNCe+5sHy5wrveMY7mMr/uy+1zaE1hbJRHeb4+S+fMVGy18UyDZZoq1fY979ZSTQzd+tblsYc2MQ0IT3IubIVqzdRWtBbFUQxMa8/U1iyQh51SjUxtgwJ1MhcMHRwL0YjydDkPUlrrPMqjtVR9xdQlGjcg7eX+GMIx/4uwT4IwqqBlCPejpzOePxcgnJfhB0e4AEP+BQGNsEuiCYYdNA/cAC2GbVyL4c1qJqqNYxq2iacv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product Name" = _t, Price = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Product Name", type text}, {"Price", Int64.Type}, {"Date", type date}})
in
#"Changed Type"

 

Meassure:

Avg Price = AVERAGE(Table1[Price])

 

Thanks in advance for any help.

 

This is the current behavior:

 

  • Hi arlequin71 

     

    You need to add an independent Product table to the model. This means there is no relationship between Product table and Table1. Use Product table's product name column in the slicer. 

     

    Then modify the measure into below

    Avg Price % difference from selected product = 
    VAR __SELECTED_PRODUCT = VALUES('Product'[Product Name])
    VAR __BASELINE_VALUE = CALCULATE([Avg Price], 'Table1'[Product Name] IN __SELECTED_PRODUCT)
    VAR __MEASURE_VALUE = [Avg Price]
    RETURN
        IF(
            NOT ISBLANK(__MEASURE_VALUE),
            DIVIDE(__MEASURE_VALUE - __BASELINE_VALUE, __BASELINE_VALUE)
        )

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

2 Replies

  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi arlequin71 

     

    You need to add an independent Product table to the model. This means there is no relationship between Product table and Table1. Use Product table's product name column in the slicer. 

     

    Then modify the measure into below

    Avg Price % difference from selected product = 
    VAR __SELECTED_PRODUCT = VALUES('Product'[Product Name])
    VAR __BASELINE_VALUE = CALCULATE([Avg Price], 'Table1'[Product Name] IN __SELECTED_PRODUCT)
    VAR __MEASURE_VALUE = [Avg Price]
    RETURN
        IF(
            NOT ISBLANK(__MEASURE_VALUE),
            DIVIDE(__MEASURE_VALUE - __BASELINE_VALUE, __BASELINE_VALUE)
        )

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.