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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
iluvcoding_91
Helper I
Helper I

DAX code to select 3 minimum values across matrix row, then return a concatenation of said values

Hello, thank you all for taking the time to reply to my post. I am looking for help in writing a DAX code which iterates through a matrix row and selects the top three minimum values, then returns a concatenation of the three minimum values in text for. For example, the table below returns the three minimum values for each row of the matrix:

iluvcoding_91_1-1648563656914.png

 

I've tried setting up a DAX code using a combination of variables, temp tables, MINX, and concatentation, but the concatentation will only pick up the first piece of text and will leave out the remaining piece of text. Any help would be greatly appreciated!!

 

Test =
VAR COL = [COL]
VAR HOUSING = [HOUSING]
VAR GASOLINE = [GAS]
VAR FOOD = [FOOD]
VAR VEHICLE = [VEHICLE]
VAR HEALTHCARE = [HEALTHCARE
VAR Temp_Tbl = {COL, HOUSING, GASOLINE, FOOD, VEHICLE, HEALTHCARE}
VAR Min_Value_1 =
MINX( Temp_Tbl, [Value])
VAR Min_Column_1 =
{
SWITCH(
Min_Value_1,
COL, "COL",
HOUSING, "HOUSING",
GASOLINE, "GASOLINE",
FOOD, "FOOD",
VEHICLE, "VEHICLE",
HEALTHCARE, "HEALTHCARE"
)
}

VAR Min_Value_2 =
MINX( Temp_Tbl, [Value])+1
VAR Min_Column_2 =
{
SWITCH(
Min_Value_2,
COL, "COL",
HOUSING, "HOUSING",
GASOLINE, "GASOLINE",
FOOD, "FOOD",
VEHICLE, "VEHICLE",
HEALTHCARE, "HEALTHCARE"
)
}

Return
Min_Column_1&", "&Min_Column_2

 

1 ACCEPTED SOLUTION

Create a new measure as

Minimum Three =
var tmpTable = { ( "Cost of living", SELECTEDVALUE('Table'[Cost of living])), 
( "Housing", SELECTEDVALUE('Table'[Housing]))
... etc
}
return CONCATENATEX( TOPN( 3, tmpTable, [Value2], ASC), [Value1], ", ")

View solution in original post

8 REPLIES 8
johnt75
Super User
Super User

I think it should work if you wrap each column reference inside SELECTEDVALUE

How would I set that up?

Create a new measure as

Minimum Three =
var tmpTable = { ( "Cost of living", SELECTEDVALUE('Table'[Cost of living])), 
( "Housing", SELECTEDVALUE('Table'[Housing]))
... etc
}
return CONCATENATEX( TOPN( 3, tmpTable, [Value2], ASC), [Value1], ", ")

Thanks, but that didn't work b/c the columns in the matrix are measure and not actual columns in the data model. Is there another function I can use instead of selectedvalues?

Just use [Cost of living] instead of the column reference. The measures should each be calculated in the correct context from the matrix visual, so it should work

Thank you so much!!! That worked!!

johnt75
Super User
Super User

You could try adding a calculated column as

Minimum Three =
var tmpTable = { ( "Cost of living", 'Table'[Cost of living]), 
( "Housing", 'Table'[Housing])
... etc
}
return CONCATENATEX( TOPN( 3, tmpTable, [Value2], ASC), [Value1], ", ")

Hi, thank you for your reply. Is there a way to set this up w/o using calculated columns and using a measure only? I have a live connection to the datasource so unfortunately I can't created calculated columns...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.