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 September 15. Request your voucher.

Reply
Anonymous
Not applicable

DAX Aggregated and sorted data (from multiply rows)

Hallo,

 

I want to concatenate some columns and aggregate and sort them according to value from other column.

To better describe some example:

(I took the example from offical documentation site for SelectColumns https://msdn.microsoft.com/query-bi/dax/selectcolumns-function-dax)

For the following table named Info:

Country State Count Date Total
INDJK2003.01.2010800
INDMH2501.01.20101000
INDWB1002.01.2010900
USACA504.01.2010500
USAWA1005.01.2010900

 

 I want to get following results. The states are aggregarted for each country, but sorted according to the date columne:

Country States

INDMH; WB; JK
USACA;WA

 

I want that it works dynamicly so I cannot use here Power Query M or Calculated Columns. How can I achieve it with DAX ????

 

Many Thanx in advance

2 ACCEPTED SOLUTIONS
Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @Anonymous

 

Please try the following calculated measure and drag to a table visual along with your [Country] field.

 

Measure = 
    CONCATENATEX(
        'Table1',
        'Table1'[State],
        ";",
        'Table1'[Date]
        )

 

image.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

concat.pngHi @Anonymous

 

If you want the value in your source table, please try the following calculated column

 

New Column = 
    CONCATENATEX(
        FILTER('Table1','Table1'[Country] = EARLIER('Table1'[Country])
        ) ,
        'Table1'[State] ,
        ";" ,
        Table1[Total]
    )

However this will not respect slicers.  If you want a dynamic calculation to respect slicers, please use the measure I posted inititally.

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
Phil_Seamark
Microsoft Employee
Microsoft Employee

HI @Anonymous

 

Please try the following calculated measure and drag to a table visual along with your [Country] field.

 

Measure = 
    CONCATENATEX(
        'Table1',
        'Table1'[State],
        ";",
        'Table1'[Date]
        )

 

image.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Thanks a lot 🙂 Maybe one more trivial question. I need the row that I calculate in that measure again in my source table:

Country State Count Date Total Aggregated

INDJK2005.01.2010800MH;WB;JK
INDMH2501.01.20101000MH;WB;JK
INDWB1002.01.2010900MH;WB;JK
USACA504.01.2010500CA;WA
USAWA1005.01.2010900CA;WA

 

 

That is what I want to achieve. Additionally if I for example add A slicer for dates 01.01.2010 - 05.01.2010

If I choose the slicer 01.01.2010 - 04.01.2010, the table should look like that:

 

Country State Count Date Total Aggregated

INDMH2501.01.20101000MH;WB
INDWB1002.01.2010900MH;WB
USACA504.01.2010500CA

 

How to achieve that , I tried to add ALL to my measure but then I get all the States in one row, no matter which country it is or if there are any other filters used. @Phil_Seamark Do you know how to solve this problem ??? Many thanks in advance for your help.

concat.pngHi @Anonymous

 

If you want the value in your source table, please try the following calculated column

 

New Column = 
    CONCATENATEX(
        FILTER('Table1','Table1'[Country] = EARLIER('Table1'[Country])
        ) ,
        'Table1'[State] ,
        ";" ,
        Table1[Total]
    )

However this will not respect slicers.  If you want a dynamic calculation to respect slicers, please use the measure I posted inititally.

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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