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

View all the Fabric Data Days sessions on demand. View schedule

Reply
mmm286b
Helper I
Helper I

Measure to calculate totals

Hi,

 

I have a table with these format:

Date                 Works

06/12/2024       50

05/12/2024       42

04/12/2024       13

03/12/2024       50

02/12/2024       11

24/11/2024       13

 

I've created a parameter with numeric range that indicates the days that I need to substract to calculate how may works are before these day.

For instance, if I select in the slice 5 days. It should be:

Today is 07/12, I substract 5 days -> 02/12. So it should sum until 02/12, so the result would be: 11 (02/12)+ 13(24/11) = 24

 

I'm trying to do with parameter and a measure. In the measure I put:

 

mmm286b_0-1733566216140.png

 

 

Any help please?

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @mmm286b 

 

Please try this:

Sum2 = 
VAR _today =
    DATE ( 2024, 12, 7 ) --replace with TODAY()
VAR _daysAgo = _today - [Parameter Value]
RETURN
    CALCULATE (
        SUM ( 'Table'[Works] ),
        KEEPFILTERS ( 'Table'[Date] <= _daysAgo )
    )

danextian_0-1733569397101.png

 





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

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Try this approach

  1. Create a Calendar Table with a relationship (Many to One and Single) from the Date column of the Fact table to the Date column of the Calendar Table
  2. Write this measure

Total = sum(Data[Works])

Measure = calculate([Total],datesbetween(calendar[date],minx(all(calendar),calendar[date]),today()-selectedvalue(Days selector[value])))

Hope this helps.


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

Hi @mmm286b 

 

Please try this:

Sum2 = 
VAR _today =
    DATE ( 2024, 12, 7 ) --replace with TODAY()
VAR _daysAgo = _today - [Parameter Value]
RETURN
    CALCULATE (
        SUM ( 'Table'[Works] ),
        KEEPFILTERS ( 'Table'[Date] <= _daysAgo )
    )

danextian_0-1733569397101.png

 





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.

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