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
databot_kd
Helper II
Helper II

TOTALYTD Calculation with dynamic end of month

Hi community, 

 

I am trying to create a dynamic TOTALYTD slicer which looks at the current month and minus 1 month instead of a hard coded end of year "30/6"

Current DAX - This accumulates the total upto end of June. 
 TOTAL YTD = TOTALYTD(CALCULATE(SUM(AMOUNT), Type = "Detail"),  'Calendar'[Date], "30/06")

Im trying to have the TOTAL YTD end at the current month (-1 month). Is this possible?

Tables:
Calendar 
Transaction List

Thanks in advance 

@Ahmedx 

1 ACCEPTED SOLUTION

TOTAL YTD = 
VAR _ToDay = EOMONTH(TODAY(),-1)
RETURN 
IF(MAX('Calendar'[Date])<=_ToDay,
TOTALYTD(CALCULATE(SUM(AMOUNT), Type = "Detail"),  'Calendar'[Date]))

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table.  Create a relationship (Many to One and Single) from the Date column of the Data Table to the Date column of the Calendar Table.  Write this measure

Measure = CALCULATE(SUM(AMOUNT),Type = "Detail",datesbetween(Calendar[date],date(year(today()),1,1),eomonth(today(),-1)))

Hope this helps.


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

thanks for sharing your possible solutions. 
But i havent had any success yet with those DAx's. 


Trying to write a DAX formula that rolls the sum up to a dynamic end of month date... For this month i need the Sum to stop rolling at Nov. In Jan i need it to roll up to Dec etc.


databot_kd_1-1702455367681.png

 

TOTAL YTD = 
VAR _ToDay = EOMONTH(TODAY(),-1)
RETURN 
IF(MAX('Calendar'[Date])<=_ToDay,
TOTALYTD(CALCULATE(SUM(AMOUNT), Type = "Detail"),  'Calendar'[Date]))

Thanks @Ahmedx that worked. You assistance was much appreciated. 

Ahmedx
Super User
Super User

pls try this

TOTAL YTD = 
VAR _ToDay = MONTH(EOMONTH(TODAY(),-1))
VAR _tbl = 
         {(1,2),(2,33),(3,61),(4,92),
          (5,122),(6,153),(7,183),
          (8,214),(9,245),(10,275),
           (11,306),(12,336)}
VAR _Fc = MAXX(FILTER(_tbl,[Value1]=_ToDay),[Value2])
RETURN 
CALCULATE(TOTALYTD(CALCULATE(SUM(AMOUNT), Type = "Detail"),  'Calendar'[Date], _Fc)

Hi @Ahmedx 

Thanks for your help thus far. 

I get this error when i try the above DAX

databot_kd_0-1702437381057.png

 

ok? pls try this

TOTAL YTD  = 
CALCULATE (
    CALCULATE(SUM(AMOUNT), Type = "Detail"),
    VAR FirstFiscalMonth =  MONTH(EOMONTH(TODAY(),-1))
    VAR LastDay = MAX('Calendar'[Date])
    VAR LastMonth = MONTH(LastDay)
    VAR LastYear = YEAR(LastDay) - IF(LastMonth < FirstFiscalMonth, 1)
    RETURN DATESBETWEEN (
        'Calendar'[Date],
        DATE(LastYear, FirstFiscalMonth, 1),
        LastDay
    )
)
Ahmedx
Super User
Super User

pls try this'

TOTAL YTD = 
VAR _ToDay = EOMONTH(TODAY(),-1)
RETURN 
IF(MAX('Calendar'[Date])<=_ToDay,
TOTALYTD(CALCULATE(SUM(AMOUNT), Type = "Detail"),  'Calendar'[Date], "30/06"))
Ahmedx
Super User
Super User

pls try this

TOTAL YTD = 
VAR _ToDay = EOMONTH(TODAY(),-1)
RETURN
CALCULATE(TOTALYTD(CALCULATE(SUM(AMOUNT), Type = "Detail"),  'Calendar'[Date], "30/06"),'Calendar'[Date] <=_ToDay)

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.