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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
HDEUISSS
Regular Visitor

Write a measure with cumulated values until selected month

Hi everybody,

 

I am trying to write a measure and I just dont get it correctly.

 

I have a very simple sample to show my problem. This is my sample data:

 

SampleSample

What I want is, that people can select a single month and then all the sold objects are cumulated until the selected month for this year per seller.

 

I have tried different measures:

 

1.) I tried using a filter like this

SumUntil = 
var m = month(max('Sample'[Date]))
var y = year(max('Sample'[Date]))
return CALCULATE(sum('Sample'[Price]),filter(all('Sample'),and(YEAR('Sample'[Date]) = y,MONTH('Sample'[Date]) <= m)))

 the date filter works but because I used all I also loose the context of the seller. This is the result:
Date FilterDate Filter

 

2.) I tried to remove the filter context only for the Date Month (Hierarchy) column:

SumUntil = 
var m = month(max('Sample'[Date]))
var y = year(max('Sample'[Date]))
return CALCULATE(sum('Sample'[Price]),all('Sample'[Date].[Monat]))

 

This way I get the correct filter for the seller but loose the year and month filter.

This is the result:

HDEUISSS_0-1668081902989.png

 

 

3.) I tried to combine both as this should be the way to go then, but I had no luck:

SumUntil = 
var m = month(max('Sample'[Date]))
var y = year(max('Sample'[Date]))
return CALCULATE(sum('Sample'[Price]),filter(all('Sample'),and(YEAR('Sample'[Date]) = y,MONTH('Sample'[Date]) <= m)),all('Sample'[Date].[Monat]))


can someone point me into the correct direction? What am I missing? Thanks!

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @HDEUISSS ;

You could create a table by dax first.

seller = VALUES('Sample'[Seller])

Then create a measure.

SumUntil2 = 
IF(ISINSCOPE('seller'[Seller]),
CALCULATE(SUM('Sample'[Price]),FILTER(ALL('Sample'),MONTH([Date])<=MONTH(MAX('Sample'[Date]))&&YEAR([Date])=YEAR(MAX('Sample'[Date]))&&[Seller]=MAX('seller'[Seller]))),
CALCULATE(SUM('Sample'[Price]),FILTER(ALL('Sample'),MONTH([Date])<=MONTH(MAX('Sample'[Date]))&&YEAR([Date])=YEAR(MAX('Sample'[Date])))))

The final show:

vyalanwumsft_0-1668407844605.png

 

View solution in original post

5 REPLIES 5
v-yalanwu-msft
Community Support
Community Support

Hi, @HDEUISSS ;

You could create a table by dax first.

seller = VALUES('Sample'[Seller])

Then create a measure.

SumUntil2 = 
IF(ISINSCOPE('seller'[Seller]),
CALCULATE(SUM('Sample'[Price]),FILTER(ALL('Sample'),MONTH([Date])<=MONTH(MAX('Sample'[Date]))&&YEAR([Date])=YEAR(MAX('Sample'[Date]))&&[Seller]=MAX('seller'[Seller]))),
CALCULATE(SUM('Sample'[Price]),FILTER(ALL('Sample'),MONTH([Date])<=MONTH(MAX('Sample'[Date]))&&YEAR([Date])=YEAR(MAX('Sample'[Date])))))

The final show:

vyalanwumsft_0-1668407844605.png

 

v-yalanwu-msft
Community Support
Community Support

Hi, @HDEUISSS ;

Try it.

 

SumUntil = 
IF(ISINSCOPE('Sample'[Seller]),
CALCULATE(SUM('Sample'[Price]),FILTER(ALL('Sample'),MONTH([Date])<=MONTH(MAX('Sample'[Date]))&&YEAR([Date])=YEAR(MAX('Sample'[Date]))&&[Seller]=MAX('Sample'[Seller]))),
CALCULATE(SUM('Sample'[Price]),FILTER(ALL('Sample'),MONTH([Date])<=MONTH(MAX('Sample'[Date]))&&YEAR([Date])=YEAR(MAX('Sample'[Date])))))

The final show:

vyalanwumsft_0-1668135087821.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yalanwu-msft I tested it and it works as you said, but my expected output would be to show also people who sold something in january, but currently in shows only the cumulated sum for people that actually sold something in february.
But I need to show also people that sold something in the past (because its cumulated it need to catch all people).
Thanks for you help.

HDEUISSS
Regular Visitor

Hi@Greg_Deckler , thanks for your quick suggestion, unfortuntely, this way I loose for example the seller mike, which had sold something in January, when selecting February. other sellers that actually sold something in february are correct.

HDEUISSS_0-1668083217452.png

 

Greg_Deckler
Community Champion
Community Champion

@HDEUISSS Try:

SumUntil = 
  VAR __d = MAX('Sample'[Date])
  VAR __s = MAX('Sample'[Seller])
  VAR __t = FILTER(ALL('Sample'), [Date] <= __d && [Seller] = __s)
  VAR __r = SUMX(__t, [Price])
RETURN
  __r


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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.