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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
ffiore
Regular Visitor

calculation of a table from a table with selection

hi, after many attempts of solving it, I post my request.

I have a table with 2 columns [SupplierID] and [ItemID]. In my dashboard, I would like the user to select one or more items (first item set) from a table visual, get the corresponding set of suppliers' names ("first supplier set"), find all the articles supplied by the suppliers in the "first supplier set" (to determine "a second item set"), and then finally find all the suppliers capable of suppling at least one item of the "second Item set". This is the iteration:

ffiore_0-1688548257021.png

 

I hope it's clear enough.
many thanks for your help

ffiore

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

First you'd need to create a helper table with all the distinct values of Item ID. This shouldn't be related to any other tables, you would only use it in the slicer for the user's initial selection.

Then you can create a measure like

Supplier is visible =
VAR CurrentSupplier =
    SELECTEDVALUE ( 'Supplier'[Supplier ID] )
VAR SelectedItems =
    TREATAS ( VALUES ( 'Helper Items'[Item ID] ), 'Supplier'[Item ID] )
VAR FirstSupplierSet =
    CALCULATETABLE ( VALUES ( 'Supplier'[Supplier ID] ), SelectedItems )
VAR SecondItemSet =
    CALCULATETABLE (
        VALUES ( 'Supplier'[Item ID] ),
        REMOVEFILTERS ( 'Supplier' ),
        FirstSupplierSet
    )
VAR FinalSuppliers =
    CALCULATETABLE (
        VALUES ( 'Supplier'[Supplier ID] ),
        REMOVEFILTERS ( 'Supplier' ),
        SecondItemSet
    )
VAR Result =
    IF ( CurrentSupplier IN FinalSuppliers, 1, 0 )
RETURN
    Result

and use this as a visual level filter on a table with columns from the supplier table, set to only show when the value is 1.

View solution in original post

4 REPLIES 4
ffiore
Regular Visitor

it works like a charm!
thank you!!

johnt75
Super User
Super User

First you'd need to create a helper table with all the distinct values of Item ID. This shouldn't be related to any other tables, you would only use it in the slicer for the user's initial selection.

Then you can create a measure like

Supplier is visible =
VAR CurrentSupplier =
    SELECTEDVALUE ( 'Supplier'[Supplier ID] )
VAR SelectedItems =
    TREATAS ( VALUES ( 'Helper Items'[Item ID] ), 'Supplier'[Item ID] )
VAR FirstSupplierSet =
    CALCULATETABLE ( VALUES ( 'Supplier'[Supplier ID] ), SelectedItems )
VAR SecondItemSet =
    CALCULATETABLE (
        VALUES ( 'Supplier'[Item ID] ),
        REMOVEFILTERS ( 'Supplier' ),
        FirstSupplierSet
    )
VAR FinalSuppliers =
    CALCULATETABLE (
        VALUES ( 'Supplier'[Supplier ID] ),
        REMOVEFILTERS ( 'Supplier' ),
        SecondItemSet
    )
VAR Result =
    IF ( CurrentSupplier IN FinalSuppliers, 1, 0 )
RETURN
    Result

and use this as a visual level filter on a table with columns from the supplier table, set to only show when the value is 1.

Hi, 

I would like the same, but
1. allowing selection of multiple values by the user (e.g. he clicks on 2 or more Item ID's), and
2. FirstSupplierSet has multiple values (e.g. Supplier1, Supplier32, Supplier54...)
this code dosesn't seem to handle this.
thank you

It should work for multiple items as well, unless the requirements are different. The first supplier set would consist of suppliers who supply any of the selected items.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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