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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
Antonio195754
Helper IV
Helper IV

How to Aggregate months from one column and total sales from another column

Hello i have a dataset like the one below, and i'm trying to aggregate the months and respective sales, as well as formatting the months, as seen in the second table.  I can do this with reference tables or group function, but i'm trying to do this with DAX.

 

Can someone please help me with the DAX?  Thank you

 

MonthSales
July 01 20034
July 02 20035
July 03 20038
August 07 200311
August 09 20036
August 12 20039
September 07 20038
September 10 20035

 

MonthSales
Jul 0317
Aug 0326
Sep 0313
1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Antonio195754 ,

 

The approach depends on whether your month column is actually a date or a text.
If a date:

Month2 = 
FORMAT ( 'Table'[Month], "mmm yy" )
Sort =
FORMAT ( 'Table'[Month], "yyyymm" )

If a text:

Month2 =
FORMAT ( DATEVALUE ( 'Table'[Month2] ), "mmm yy" )
Sort =
FORMAT ( DATEVALUE ( 'Table'[Month2] ), "yyyymm" )

 

Since either of those formula will return a text string, the values will be sorted alphabetically thus the need for a custom column sort.


 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

5 REPLIES 5
danextian
Super User
Super User

Hi @Antonio195754 ,

 

The approach depends on whether your month column is actually a date or a text.
If a date:

Month2 = 
FORMAT ( 'Table'[Month], "mmm yy" )
Sort =
FORMAT ( 'Table'[Month], "yyyymm" )

If a text:

Month2 =
FORMAT ( DATEVALUE ( 'Table'[Month2] ), "mmm yy" )
Sort =
FORMAT ( DATEVALUE ( 'Table'[Month2] ), "yyyymm" )

 

Since either of those formula will return a text string, the values will be sorted alphabetically thus the need for a custom column sort.


 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

That was so simple.  It worked like a charm.  Created both columns and then sorted off the sort column, aggregated my months with the sales rolling up to it.  Thank you!

The date field was in date format, so went with your first suggestion.

Ashish_Mathur
Super User
Super User

Hi,

Ensure that the Month column has proper right aligned dates.  Create a Calendar Table with calculated column formulas for Year, Month name and Month number.  Sort the Month name by the Month number.  To your visual, drag Year and Month name from the Calendar Table.  Write this measure

Total = sum(Data[Sales])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey @Ashish_Mathur yes i did it that way originally and it worked, but to improve my DAX skills, i'm trying to accomplish it that way.  Any suggestions?  The date field comes in as date format.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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