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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Roshan_201295
Helper I
Helper I

How to get dynamically last to Current month 1st to Max date KPIs calc for Each Month In Matrix?

Hi There, 

I am getting an issue while solving problem for calculating Sum of accounts from current month and last months form the dates (1 to Max(date)-1).


I working on matrix visual and Matrix visual contains businesses names at the Row Header and Column header contains the DISB_MONTH. I would like to get the current month (1st Aug , Max-1 Aug ) and last month (1st , Max-1 ) but & for last months its should work for each last months like Jul,jun,may,apr,mar,feb,jan.
I tring but showing blank and not dynamically spreaded accross this criteria like (1st to Max)
For ur references I providing an imageissue.png
Please help me in that deadline is very close 🙏

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

Hi @Roshan_201295,

Thank you @Shahid12523 @rohit1991, for your insights.

I have replicated your scenario using sample data from my end and obtained the following output. I've attached the pbix file for your reference.

vsaisraomsft_0-1755856023031.png

I hope this is helpful.

Thank you.

View solution in original post

6 REPLIES 6
v-saisrao-msft
Community Support
Community Support

Hi @Roshan_201295,

We haven’t heard back from you in a while regarding your issue. let us know if your issue has been resolved or if you still require support.

 

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @Roshan_201295,

Checking in to see if your issue has been resolved. let us know if you still need any assistance.

 

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @Roshan_201295,

Have you had a chance to review the solution we shared earlier? If the issue persists, feel free to reply so we can help further.

 

Thank you.

v-saisrao-msft
Community Support
Community Support

Hi @Roshan_201295,

Thank you @Shahid12523 @rohit1991, for your insights.

I have replicated your scenario using sample data from my end and obtained the following output. I've attached the pbix file for your reference.

vsaisraomsft_0-1755856023031.png

I hope this is helpful.

Thank you.

Shahid12523
Community Champion
Community Champion

Use a dynamic DAX measure like this

 

LMTD Accounts =
VAR _MonthStart = STARTOFMONTH('Date'[Date])
VAR _MonthEnd =
MIN(
MAX('Date'[Date]) - 1,
ENDOFMONTH('Date'[Date])
)
RETURN
CALCULATE(
SUM(Accounts[Amount]),
DATESBETWEEN('Date'[Date], _MonthStart, _MonthEnd)
)

Shahed Shaikh
rohit1991
Super User
Super User

Hi @Roshan_201295 

Could you Please follow the Steps below:

Create a proper Date table and mark it as a Date table.

Build a measure for Accounts = SUM(Fact_Disbursements[Accounts])

 

Create an Anchor Day measure:

Anchor Date = CALCULATE(MAX(Fact_Disbursements[Disb_Date]), ALL(Dim_Date))
Anchor Day (minus 1) = DAY([Anchor Date]) - 1

 

MTD measure:

MTD (1..Max-1) =
VAR AnchorDay = [Anchor Day (minus 1)]
VAR MonthStart = DATE(SELECTEDVALUE(Dim_Date[Year]), SELECTEDVALUE(Dim_Date[MonthNumber]),1)
VAR MonthEnd   = EOMONTH(MonthStart,0)
VAR EndDate    = DATE(YEAR(MonthStart),MONTH(MonthStart),MIN(DAY(MonthEnd),AnchorDay))
RETURN CALCULATE([Accounts], DATESBETWEEN(Dim_Date[Date],MonthStart,EndDate))

 

LMTD measure (previous month):

LMTD (Prev Mth 1..Max-1) =
VAR AnchorDay = [Anchor Day (minus 1)]
VAR CurrMonthStart = DATE(SELECTEDVALUE(Dim_Date[Year]),SELECTEDVALUE(Dim_Date[MonthNumber]),1)
VAR PrevMonthStart = EOMONTH(CurrMonthStart,-1)+1
VAR PrevMonthEnd   = EOMONTH(PrevMonthStart,0)
VAR EndDate        = DATE(YEAR(PrevMonthStart),MONTH(PrevMonthStart),MIN(DAY(PrevMonthEnd),AnchorDay))
RETURN CALCULATE([Accounts],DATESBETWEEN(Dim_Date[Date],PrevMonthStart,EndDate))

Now, drop Business on Rows, MonthYear on Columns, and both measures in Values. The table will automatically calculate each month’s MTD (1 to Max-1) and the previous month’s LMTD dynamically. You can also add a simple

 

variance measure:

MoM Variance = [MTD (1..Max-1)] - [LMTD (Prev Mth 1..Max-1)]

This setup ensures your Matrix always respects the same cut-off day (Max-1), works across months, and stays dynamic as new data comes in.

 

image.png


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors