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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
micwed
New Member

How to calculate the sum of the last 6 month?

Hi,

 

I am very new to DAX and it it is realy hard to understand fom me. Maybe somebody can give me an example or link to the answer of the same question. 

 

I want to calculate the sum of quantity of the last 6 month

Usualy I would try as in any other language: Measure = CALCULATE([Sum of Quantity], 'Date'[Date]>=DATEADD(TODAY(),-6,month))

It should be a very simple formular, honestly it isn't.

How can I do this, without adding claculated columns just within a measure. Just in one measure.

 

Thanks in advance!

 

Mike

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@micwed Try this:

Last 6 Months Measure =
  VAR __Today = TODAY()
  VAR __SixMonthsAgo = EOMONTH(__Today,-7) + 1
  VAR __Table = FILTER('Table',[Date]>=__SixMonthsAgo && [Date]<=__Today)
  VAR __Result = SUMX(__Table,[Quantity])
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...

Hi Greg,

 

thank you very much for your answer!

 

After a wile I found a solution that fits to my needs.

I used

Sum of Quantity = SUM(Sales[Quantity])

Sold Quantity = CALCULATE([Sum of Quantity],DATESINPERIOD('Date'[Date],TODAY(),-6, MONTH))
Yes of course this is rolling month, but its okay in this case. Is there any advantagas or disadvantages on your way or my way?
 
Best regards,
Mike

I'm exceptionally new to DAX and it is realy hard to comprehend fom me. Perhaps someone can offer me a model or connection to the response of a similar inquiry.

@belanoor @micwed Can you provide sample data. By way of explanation in terms of the formula:

Last 6 Months Measure =
  VAR __Today = TODAY()
// Get today's date

  VAR __SixMonthsAgo = EOMONTH(__Today,-7) + 1 
// Goes back 7 months (end of month) + 1 is the first of the month 6 months ago

  VAR __Table = FILTER('Table',[Date]>=__SixMonthsAgo && [Date]<=__Today) 
// filter the table such that all dates between today's date and six months ago

  VAR __Result = SUMX(__Table,[Quantity])
// Sum up the Quantity column for all rows

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...

Hi Greg,

 

I just saw, that probably I can't use your solution, because I have my data stored in a star-schema and have no generic Date column in my Sales data, but you assume it, right?

 

micwed_2-1674050444989.png

Here just a small part of my model

 

 

Best,

 

Mike

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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