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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Simonn97_PBI
Advocate I
Advocate I

Cash flow YTD/MTD calculation issue with prior year P12 dependency

Hi

 

Problem description
I have fact tables that contain only YTD values for cash flow payables. For further business calculations, I need to calculate MTD values.
Example logic:

  • For P1 → P1 YTD – P12 LY YTD

  • For P2 → P2 YTD – P1 YTD, etc.

Data model

  • Classic star schema

  • A disconnected date table used as a slicer

  • Data source is Excel → Data Lake → Power BI

Main issue

  • Calculating MTD based on dates selected in the slicer, especially for P1.

Secondary issue

  • Region mapping changes cause problems when calculating MTD in SQL with window functions. I get incorrect values for rows where the mapping changes.

  • Current workaround: fix the mapping in Excel.

  • Mapping is built from the fact table and extended with an additional column provided by the business.

  • I’m not sure if this can only be solved by maintaining the Excel mapping, or if there’s a better way to handle this in Power BI.

Below are my basic measures. I didn’t include the others because when I try using PREVIOUSMONTH, I can’t properly control the filter context.

 

AC Total = 

VAR _result =
    CALCULATE (
         SUM('Fact Additions'[Value]),
        FILTER ( dimDate, dimDate[Date] >= [Stop date Min] && dimDate[Date] <= [Stop date] ),
        REMOVEFILTERS ( dimVersion ),
        dimVersion[Version_ind] = "AC"
    )
RETURN
    _result 


Stop date = 
MAX ( dimDatedisc[Date] )

Stop date Min = 
MIN(  dimDatedisc[FinancialYearStartDate])

 

1 ACCEPTED SOLUTION

Hi,

PBI file attached.

Ashish_Mathur_0-1757472889788.png

 


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

View solution in original post

8 REPLIES 8
Poojara_D12
Super User
Super User

Hi @Simonn97_PBI 

I see the problem — your fact table only holds YTD values, but the business needs MTD values, which means you essentially need to compute differences between cumulative balances. Since YTD is cumulative, the way to get MTD is by subtracting the prior period’s YTD from the current period’s YTD. In DAX, the challenge is controlling filter context correctly, especially because you’re using a disconnected date table as a slicer. That means your measures don’t automatically respect time-intelligence functions like PREVIOUSMONTH, which is why you’re running into issues.

 

A clean way to solve this is to first calculate your YTD measure correctly (you already have AC Total doing that). Then, for MTD, instead of trying to use PREVIOUSMONTH directly, you can create a measure that calculates the difference between the current period’s YTD and the prior period’s YTD. For example:

AC MTD =
VAR _currentYTD =
    [AC Total]
VAR _previousYTD =
    CALCULATE (
        [AC Total],
        DATEADD ( dimDate[Date], -1, MONTH )   -- shifts the context by one month
    )
RETURN
    _currentYTD - _previousYTD

This approach ensures:

For P1, DATEADD correctly moves into the prior year (P12 of LY), giving you the right subtraction.

For P2 onward, it always subtracts the immediately preceding month’s YTD.

 

The key here is that you must base the calculation on your fact-driven YTD measure (AC Total) rather than directly re-summing the fact table again. This way, you can reuse your existing logic and only focus on the period shift.

 

For the secondary issue with region mapping changes, your current workaround (fixing mappings in Excel) is common but not scalable. A better long-term solution is to build a slowly changing dimension (SCD) style region mapping table, where each mapping change is stored with a validity period (StartDate / EndDate). You can then join or filter against this table in Power BI so the MTD and YTD measures respect the correct region mapping over time. This avoids incorrect results when mappings change historically, because each row in your fact table will resolve to the correct region for that period.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
GeraldGEmerick
Super User
Super User

@Simonn97_PBI See if this works for you:

AC Total = 
VAR _stopmin = [Stop date Min]
VAR _stopdate = [Stop date]
VAR _result =
    CALCULATE (
        SUM('Fact Additions'[Value]),
        FILTER ( dimDate, dimDate[Date] >= _stopmin && dimDate[Date] <= _stopdate ),
        REMOVEFILTERS ( dimVersion ),
        dimVersion[Version_ind] = "AC"
    )
RETURN
    _result 

It’s not about a cumulative value like in your case, but about achieving the numbers shown below (example).

 
 
periodytdmtd change
p1223 
p1263
p224-2
p315-9
p413-2
p5207
p63111
p7332
p825-8
p915-10
p10227
p11253
p1211-14

Hi,

Is there no date or month column in your source data table?


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

Every month there is a new Excel file, and based on the ETL in the data lake, a standard datekey is assigned.

 

Share the data with the datekey


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

Hi,

PBI file attached.

Ashish_Mathur_0-1757472889788.png

 


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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.