Forum Discussion

magnusks's avatar
magnusks
Icon for Helper I rankHelper I
2 years ago
Solved

Combine concatenatex and selectedvalue

Hi all. 

I have a table showing workhours per employee. Each employee might work on various projects and at different departments at the company. I have a factstbl where the workhours are stored, and two dimtbls where one has info regarding projects and the other regarding departments (plus some other stuff). 

 

Table name: DimProjects  Table name: DimEmpl  

Table name: Facts

  
ProjectProjectKey EmplDep EmplProjectKeyHours
137281 18a 18153
108672 15b 15287
166513 26c 26390
100384 91d 91453
186435 13e 13584
185586 90f 90697
156827 38g 38796
147188 10h 10879
148969 80i 80952
1978410 2j 21070


I have a stacked coloumnchart that shows the amount of hours worked per department per year (have a datetable too). In addition to this I want to show as a tooltip the projects that the employees for each department has worked on. 

I have tried to create a measure for this (below). If I put the measure into a table I get the "NA" as expected when I dont filter one department. But as soon as I filter on department the table crashes. In addition, the measure causes the barchart to "crash" when I place it as a tooltip.  

 

 

List of projects = 
var _conc = 
CONCATENATEX(
        DimProjects,DimProjects[Project])

var _selected =
SELECTEDVALUE(DimEmpl[Dep])

var _result = 
IF(_selected, _conc, "NA")

RETURN
_result

 

 

 

I cant wrap my head around where Im going wrong. Any suggestions?

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  magnusks ,

     

    Here's another idea, you can also try the following.

    1. Create calculated table -- use the columns of the new table as slicers.

     

    Table =
    DISTINCT('DimEmpl'[Dep])

     

    2. Create measure.

     

    List of projects =
    var _select=SELECTCOLUMNS('Table',"Dep",'Table'[Dep])
    var _empl=
    SELECTCOLUMNS(
        FILTER(ALL('DimEmpl'),'DimEmpl'[Dep] in _select),"emp",'DimEmpl'[Empl])
    var _projectkey=
    SELECTCOLUMNS(
        FILTER(ALL('Facts'),'Facts'[Empl] in _empl),"projectkey",'Facts'[ProjectKey])
    var _con=
    CONCATENATEX(
        FILTER(ALL('DimProjects'),
        'DimProjects'[ProjectKey] in _projectkey),'DimProjects'[Project],"-")
    return
    IF(
       NOT( MAX('DimEmpl'[Dep])) in _select,BLANK(),
       IF(
    ISFILTERED('Table'[Dep]),_con,
    "Na")
    )

     

    3. Result:

     

     

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

8 Replies

  • Hi magnusks ,

     

    I see that if condition does not have any condition in the first parameter. Can you use the following code where we check the selected value is equal to the concatenated value?

    var _result = 
    IF(_selected = _conc, _conc, "NA")

     

    • magnusks's avatar
      magnusks
      Icon for Helper I rankHelper I

      Hi govindarajan_d ,

       

      Thanks for the quick reply. 

       

      I swapped the "var _result" with the code you suggested, when I did the measure returns all projects. Not sure if that is what you wanted to know?

      • magnusks's avatar
        magnusks
        Icon for Helper I rankHelper I

        govindarajan_d ,

         

        Sorry it seems I was a little bit to quick to paste in your measure. The measure now returns NA, not the list of all projects.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  magnusks ,

     

    Here's another idea, you can also try the following.

    1. Create calculated table -- use the columns of the new table as slicers.

     

    Table =
    DISTINCT('DimEmpl'[Dep])

     

    2. Create measure.

     

    List of projects =
    var _select=SELECTCOLUMNS('Table',"Dep",'Table'[Dep])
    var _empl=
    SELECTCOLUMNS(
        FILTER(ALL('DimEmpl'),'DimEmpl'[Dep] in _select),"emp",'DimEmpl'[Empl])
    var _projectkey=
    SELECTCOLUMNS(
        FILTER(ALL('Facts'),'Facts'[Empl] in _empl),"projectkey",'Facts'[ProjectKey])
    var _con=
    CONCATENATEX(
        FILTER(ALL('DimProjects'),
        'DimProjects'[ProjectKey] in _projectkey),'DimProjects'[Project],"-")
    return
    IF(
       NOT( MAX('DimEmpl'[Dep])) in _select,BLANK(),
       IF(
    ISFILTERED('Table'[Dep]),_con,
    "Na")
    )

     

    3. Result:

     

     

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • magnusks's avatar
      magnusks
      Icon for Helper I rankHelper I

      Anonymous ,

       

      Thank you. That worked! 🙂