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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
hassanh2
Helper I
Helper I

Dax function to concatenate records from multiple rows

Hello,

 

can someone help please with the following!

I have the first 2 columns generated from a datasource, im trying to create a DAX function to create the last 3 columns. Basically for each product there can be one more colors, so 3rd column should concatenate the colors for the same (unique) products, then 4th coloum to flag the last record for each product and last column to display the count of colors in the concatenated column.

 

hassanh2_0-1698658642370.png

 

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @hassanh2 ,

 

try like:

1) add an index column in Power Query or datasource

2) add the expected calculated columns like:

ColorCon = 
CONCATENATEX(
    CALCULATETABLE(
        DISTINCT(data[Color]),
        ALLEXCEPT(data, data[Product]),
        data[Index]<=EARLIER(data[Index])
    ),
    data[Color],
    "^"
)
Flag = 
VAR _max =
MAXX(
    FILTER(data, 
        data[Product]=EARLIER(data[Product])
    ),
    data[index]
)
VAR result = IF(data[index]=_max, "Last")
RETURN result
ColorCount = 
CALCULATE(
    DISTINCTCOUNT(data[Color]),
    ALLEXCEPT(data, data[Product]),
    data[Index]<=EARLIER(data[Index])
)

 

it worked like:

FreemanZ_0-1698718326878.png

 

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @hassanh2 ,

 

try like:

1) add an index column in Power Query or datasource

2) add the expected calculated columns like:

ColorCon = 
CONCATENATEX(
    CALCULATETABLE(
        DISTINCT(data[Color]),
        ALLEXCEPT(data, data[Product]),
        data[Index]<=EARLIER(data[Index])
    ),
    data[Color],
    "^"
)
Flag = 
VAR _max =
MAXX(
    FILTER(data, 
        data[Product]=EARLIER(data[Product])
    ),
    data[index]
)
VAR result = IF(data[index]=_max, "Last")
RETURN result
ColorCount = 
CALCULATE(
    DISTINCTCOUNT(data[Color]),
    ALLEXCEPT(data, data[Product]),
    data[Index]<=EARLIER(data[Index])
)

 

it worked like:

FreemanZ_0-1698718326878.png

 

Thank you very much. This is very helpful.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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