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! Learn more

Reply
Anonymous
Not applicable

calculate cumulative value

Hi guys, I want to calculate a cumulative value with selected date range, and the slicer may switch  M to W(week) or D(day),

is there to be a good way to fullfill that? Thank you

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

I created some data:

vyangliumsft_0-1652234500854.png

Here are the steps you can follow:

1. Use Enter data to create a table.

vyangliumsft_1-1652234500856.png

2. Create a calendar table.

Date =
CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

vyangliumsft_2-1652234500857.png

3. Create measure.

Flag_day =
var _mindate=MINX(ALLSELECTED('Table'),'Table'[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),'Table'[Date])
return
IF(
MAX('Date'[Date])>=_mindate&&MAX('Date'[Date])<=_maxdate,1,0)
Flag_week =
var _mindate=MINX(ALLSELECTED('Table'),'Table'[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),'Table'[Date])
return
IF(
   MAX('Date'[Week])>=WEEKNUM(_mindate,1)&&MAX('Date'[Week])<=WEEKNUM(_maxdate,1),1,0)
Flag_month =
var _mindate=MINX(ALLSELECTED('Table'),'Table'[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),'Table'[Date])
return
IF(
MAX('Date'[Month])>=MONTH(_mindate)&&
MAX('Date'[Month])<=MONTH(_maxdate),1,0)
Flag =
var _select=SELECTEDVALUE('Table2'[Select])
return
SWITCH(
    TRUE(),
    _select="Month",[Flag_month],
    _select="Week",[Flag_week],
    _select="Day",[Flag_day])
amount_measure =
SUMX(FILTER(ALL('Table'),'Table'[Date]=MAX('Date'[Date])),[Amount])
calculate cumulative value =
SUMX(FILTER(ALL('Date'),'Date'[Date]<=MAX('Date'[Date])),[amount_measure])

4. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_3-1652234500858.png

5. Result:

Select "Month", "Week", "Day" according to the slicer, and display the corresponding measure

vyangliumsft_4-1652234500859.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi  @Anonymous ,

I created some data:

vyangliumsft_0-1652234500854.png

Here are the steps you can follow:

1. Use Enter data to create a table.

vyangliumsft_1-1652234500856.png

2. Create a calendar table.

Date =
CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

vyangliumsft_2-1652234500857.png

3. Create measure.

Flag_day =
var _mindate=MINX(ALLSELECTED('Table'),'Table'[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),'Table'[Date])
return
IF(
MAX('Date'[Date])>=_mindate&&MAX('Date'[Date])<=_maxdate,1,0)
Flag_week =
var _mindate=MINX(ALLSELECTED('Table'),'Table'[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),'Table'[Date])
return
IF(
   MAX('Date'[Week])>=WEEKNUM(_mindate,1)&&MAX('Date'[Week])<=WEEKNUM(_maxdate,1),1,0)
Flag_month =
var _mindate=MINX(ALLSELECTED('Table'),'Table'[Date])
var _maxdate=MAXX(ALLSELECTED('Table'),'Table'[Date])
return
IF(
MAX('Date'[Month])>=MONTH(_mindate)&&
MAX('Date'[Month])<=MONTH(_maxdate),1,0)
Flag =
var _select=SELECTEDVALUE('Table2'[Select])
return
SWITCH(
    TRUE(),
    _select="Month",[Flag_month],
    _select="Week",[Flag_week],
    _select="Day",[Flag_day])
amount_measure =
SUMX(FILTER(ALL('Table'),'Table'[Date]=MAX('Date'[Date])),[Amount])
calculate cumulative value =
SUMX(FILTER(ALL('Date'),'Date'[Date]<=MAX('Date'[Date])),[amount_measure])

4. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_3-1652234500858.png

5. Result:

Select "Month", "Week", "Day" according to the slicer, and display the corresponding measure

vyangliumsft_4-1652234500859.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


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

sorry, I found no ways to send you a file or link😐

Google Drive/One Drive and a host of other service providers.


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

edited

That link takes me to an error page.


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

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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