Forum Discussion

amarsale85's avatar
amarsale85
Helper II
5 years ago

PATHCONTAINS and Multiple selected value

Hi Experts,

 

i have created below measure to calculate aggregated profit amount for locations at parent level (like Continent, Country, Province) which would be summation of children cities. Our Database stores data at city level only.

 

Parent Profit Amount := 
VAR c = SELECTEDVALUE ( DimLocation[LocationKey] ) 
RETURN 
CALCULATE ( 
SUM ( FactAmount[Profit] ), 
ALL ( DimLocation ), 
PATHCONTAINS ( DimLocation[Path], c ) 
)

 

 

Now the issue is, how can i handle if there are multiple selected values ? Because here, SELECTEDVALUE () function expects a single distinct value and if its given multiple values it doesn't show anything. Suppose below data exists in Database:

 

CountryLocationKeyCityProfit Amount
England10London25
USA11London30
Canada12London45

 

And i just want to show "City" and its "Profit Amount" in chart. 

The above measure won't display anything for Location="London" because for "London" location SelectedValue() function gets 3 locationkey values "10,11,12". So in the chart London isn't shown at all.

 

Please help.

 

Regards,

Amar 

8 Replies

  • Here are some options:

     

    - use MIN/MAX instead of SELECTEDVALUE

    - use TOPN(1,FILTERS())

    - make your slicer single select.

    • amarsale85's avatar
      amarsale85
      Helper II

      Thank you for your reply.

      Is there a way to take all multiple values and apply it to the measure in PathContains() function?

      • lbendlin's avatar
        lbendlin
        Super User

        yes, convert your path into a table variable and then use INTERSECT()

  • PaulDBrown's avatar
    PaulDBrown
    Community Champion

    amarsale85 

    Apologies since I'm not familiar with the PATHCONTAINS function, but wouldn't this measure work?

    Total by city = CALCULATE([Sum of Profit], ALLEXCEPT(table, table[city]))