Forum Discussion

donodackal's avatar
donodackal
Helper I
4 years ago
Solved

Help creating measure to filter data

Hello

Is there a way I can filter the data from the below table based on how many locations a product is sold? For instance, I would like to filter the data visualised by:

  • Products sold at only one location
  • Products sold at two locations
  • Product sold at three locations
  • Products sold at all four locations.

Also, Is there a way I can add a filter to my dashboard where if I select two or more locations specifically, the data is filtered to products sold specifically to both or more locations selected (excludes products sold just to one of the selected locations)?

 

Table Name: Product Sales
Product IDNo of UnitsTotal ValueSale DateLocation
Product 11050015/07/2022Location 1
Product 2525016/07/2022Location 2
Product 3210017/07/2022Location 1
Product 4420018/07/2022Location 1
Product 1210019/07/2022Location 2
Product 2420020/07/2022Location 3
Product 3315021/07/2022Location 2
Product 4840022/07/2022Location 1
Product 1735023/07/2022Location 3
Product 2735024/07/2022Location 2
Product 3420025/07/2022Location 3
Product 4420026/07/2022Location 1
Product 1735023/07/2022Location 4
Product 2735024/07/2022Location 2
Product 3420025/07/2022Location 3
Product 4420026/07/2022Location 1

3 Replies

  • Hi,

    First create a separate, single-column table to be used as a filter which comprises integers from one up to the maximum number of locations you would like to filter for (four, in your example). Assuming this table and its only column are both named 'Unique Location Count', create this measure:

     

    MyMeasure =
    VAR UniqueLocationCount =
        SELECTEDVALUE( 'Unique Location Count'[Unique Location Count] )
    VAR MyTable =
        ADDCOLUMNS(
            SUMMARIZE( 'Product Sales', 'Product Sales'[Product ID] ),
            "Unique Locations",
                CALCULATE(
                    DISTINCTCOUNT( 'Product Sales'[Location] ),
                    ALLEXCEPT( 'Product Sales', 'Product Sales'[Product ID] )
                )
        )
    RETURN
        SUMX( MyTable, 0 + ( [Unique Locations] = UniqueLocationCount ) )

     

    which can then be dragged into the filters pane for your main visual and set equal to 1.

    Of course, you could also dynamically derive the table 'Unique Location Count' from your dataset instead of creating it statically.

    Regards

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi donodackal,

    Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or accept the helpful suggestions to help others who faced similar requirements.

    If these also don't help, please share more detailed information to help us clarify your scenario to test.

    How to Get Your Question Answered Quickly 

    Regards,

    Xiaoxin Sheng