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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
eriksjoo
Frequent Visitor

MEASURE: concatenate multiple columns based on slicer value(s)

Hello first time poster here. Been searching for a solution to my problem for several hours and was hoping you could help me.

 

I have a situation where I want the user to be able to select which values to display in a matrix visual, by selecting value(s) in a slicer and getting the result in 1 box in the matrix.

 

I have an EmployeeTable that has all the data and looks like this:

EmployeeWeekWeekdayWork OrderCommentFunction
Employee A43Monday331133XYDriver
Employee A43Wednesday331113TYYYAdmin
Employee A43Thursday444133XLEAOperator
Employee B43Tuesday419033POEDriver
Employee B43Wednesday321031FLEDriver
Employee F43Friday302131FAEAdmin
Employee F43Saturday493019MOEOperator

 

I have a SlicerTable that looks like this:

Info
Work Order
Comment
Function

 

I want the user to select any combination from these three values and getting the result in a matrix visual.

If the user selects Work Order they get this result:

EmployeeMondayTuesdayWednesdayThursdayFridaySaturdaySunday
Employee A331133 331113444133   
Employee B 419033321031    
Employee F    302131493019 

 

If they select Work Order and Comment they get this result:

EmployeeMondayTuesdayWednesdayThursdayFridaySaturdaySunday
Employee A331133
XY
 331113
TYYY
444133
XLEA
   
Employee B 419033
POE
321031
FLE
    
Employee F    302131
FAE
493019
MOE
 


If the user selects Comment and Function they should get this result:

EmployeeMondayTuesdayWednesdayThursdayFridaySaturdaySunday
Employee AXY
Driver
 TYYY
Admin
XLEA
Operator
   
Employee B POE
Driver
FLE
Driver
    
Employee F    FAE
Admin
MOE
Operator
 

 

I've started writing some DAX expressions, starting out with 1 or 2 of the columns.

I have so far:

Measure = 
IF(COUNTAX(FILTER(SlicerTable;SlicerTable[Info]="Work Order");SlicerTable[Info])>0;

    CONCATENATEX(

        VALUES(EmployeeTable[Work Order]);
        EmployeeTable[Work Order];
        ", "
   );
   ""
)

 

Measure2=

CALCULATE(
IF(COUNTAX(FILTER(SlicerTable;SlicerTable[Info]="Work Order");SlicerTable[Info])>0;
    MAX(EmployeeTable[Work Order]);
    "")&UNICHAR(10)&
IF(COUNTAX(FILTER(SlicerTable;SlicerTable[Info]="Work Order");SlicerTable[Info])>0;
    MAX(EmployeeTable[Comment])
    ;"")
)

 

Both of these measures seem to yield the same result, i.e. that they show the value regardless of the outcome of the IF. So for Measure i get the matrix with the Work Order values in every cell. For Measure 2 I get Work Order and Comment in every cell.

HOWEVER, when I create a card visual and select a cell in the matrix visual, the card displays the correct result. 

 

Does anyone have any insight into either how to write a dax expression, or enlighten me as to why the card visual displays correct information when I click on a cell in the matrix, but the matrix itself does not?

Appreciative for any support

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@eriksjoo , Create a measure like this and use

measure =
var _1 = countx(filter(SlicerTable, SlicerTable [Value] ="Work Order"),SlicerTable [Value])+0
var _2 = countx(filter(SlicerTable, SlicerTable [Value] ="Comment"),SlicerTable [Value])+0
var _3 = countx(filter(SlicerTable, SlicerTable [Value] ="Function"),SlicerTable [Value])+0

return
if(_1 >0 , max(employee[Work Order]),"") & " " & if(_2 >0 , max(employee[Comment]),"") & " " & if(_3 >0 , max(employee[Function]),"")

View solution in original post

wdx223_Daniel
Super User
Super User

@eriksjoo 

=var _s=allselected(slicer[column]) return concatenatex(table,if("work order" in _s,table[work order])&if("comment" in _s,table[comment])&if("function" in _s,table[function]),",")

View solution in original post

4 REPLIES 4
wdx223_Daniel
Super User
Super User

@eriksjoo 

=var _s=allselected(slicer[column]) return concatenatex(table,if("work order" in _s,table[work order])&if("comment" in _s,table[comment])&if("function" in _s,table[function]),",")

Thank you very much Daniel! This also worked 

amitchandak
Super User
Super User

@eriksjoo , Create a measure like this and use

measure =
var _1 = countx(filter(SlicerTable, SlicerTable [Value] ="Work Order"),SlicerTable [Value])+0
var _2 = countx(filter(SlicerTable, SlicerTable [Value] ="Comment"),SlicerTable [Value])+0
var _3 = countx(filter(SlicerTable, SlicerTable [Value] ="Function"),SlicerTable [Value])+0

return
if(_1 >0 , max(employee[Work Order]),"") & " " & if(_2 >0 , max(employee[Comment]),"") & " " & if(_3 >0 , max(employee[Function]),"")

Thank you so much! This worked brilliantly! Saved my night 🙂


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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