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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
arlequin71
Helper II
Helper II

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:

arlequin71_0-1663850547412.png

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
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)
    )

vjingzhang_0-1663918207106.png

 

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

View solution in original post

2 REPLIES 2
arlequin71
Helper II
Helper II

Excelent! Thanks so much @v-jingzhang 

v-jingzhang
Community Support
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)
    )

vjingzhang_0-1663918207106.png

 

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

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.