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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Ancella
Frequent Visitor

How to extract previous month sales as a grouped column

 

 

I'm unable to create a calculated table where I'm trying to group the following margin% by cities and arrive at 2 columns: current month margin% and previous month margin%. I have tried several formulae: previousmonth, dateadd and it does not seem to work.

please help!!

 

dataset:

 

Ancella_0-1723557129126.png

dax used:

Ancella_1-1723557155109.png

desired outcome:

image.png

 

 
1 ACCEPTED SOLUTION

@Ancella OK, see attached PBIX file below signature:

Current Month = 
    VAR __MaxMonth = MONTH( MAX( 'Table'[Beg_of_month] ) )
    VAR __Result = AVERAGEX( FILTER( 'Table', MONTH( [Beg_of_month] ) = __MaxMonth ), [Margin %] )
RETURN
    __Result

 

Last Month = 
    VAR __MaxMonth = MONTH( MAX( 'Table'[Beg_of_month] ) )
    VAR __Result = AVERAGEX( FILTER( 'Table', MONTH( [Beg_of_month] ) = __MaxMonth - 1 ), [Margin %] )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
rajendraongole1
Super User
Super User

Hi @Ancella - can you try the below calculated table and rename the source tables at your end.

CityMarginSummary =
SUMMARIZE(
    'Calct',
    'Calct'[Beg_of Month],
    'Calct'[City],
    "Current Month Margin%",
        CALCULATE(
            AVERAGE('Calct'[Margin])
        ),
    "Previous Month Margin%",
        CALCULATE(
            AVERAGE('Calct'[Margin]),
            FILTER(
                ALL('Calct'),
                'Calct'[City] = EARLIER('Calct'[City]) &&
                'Calct'[Beg_of Month] = EOMONTH(EARLIER('Calct'[Beg_of Month]), -1)
            )
        )
)

 

rajendraongole1_0-1723561770933.png

 

Hope it works, still any please share some sample data will check on this.

 





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

Proud to be a Super User!





Hi @rajendraongole1 ,

 

Thank you for the solution. But as per your table Previous month margin% seems to be empty.

Upon applying it to my dataset also I get an empty column. Can you please help with a column that would populate the column:

refer "Margin last month"

Ancella_1-1723649789400.png

 

 

@rajendraongole1 Can you share the sample data you posted as text?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , 

thank you for your response.. I can share my sample dataset, if this works. 

Please note: Margin% column is a calculated measure.. while I'm trying to create a calculated table with current month and previous month margins, none of the time intelligence functions work.. they're either showing empty results or same values as current month

 

Ancella_dataset.xlsx

Hi,

Why do you want to create a calculated table?  Why not a measure?


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

@Ancella OK, see attached PBIX file below signature:

Current Month = 
    VAR __MaxMonth = MONTH( MAX( 'Table'[Beg_of_month] ) )
    VAR __Result = AVERAGEX( FILTER( 'Table', MONTH( [Beg_of_month] ) = __MaxMonth ), [Margin %] )
RETURN
    __Result

 

Last Month = 
    VAR __MaxMonth = MONTH( MAX( 'Table'[Beg_of_month] ) )
    VAR __Result = AVERAGEX( FILTER( 'Table', MONTH( [Beg_of_month] ) = __MaxMonth - 1 ), [Margin %] )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Ancella OK, I'll take a look. In the mean time, you may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors