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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jlouvel
Frequent Visitor

MTD Running Total Sales

Hi all,

 

I have already posted regarding this problem and never really found a solution so I am going to rephrase hoping someone out there can help.

 

I am trying to build measures allowing to give me MTD Running Total Sales for the current fiscal year and the previous one.

To do so, I came up with the following measures:

 

Prev MTD Running Total Sales = 
VAR CurrentDayNumber =
    MAX(YTDInfos[CurrentDayNumber])
RETURN
    IF (
        MIN ( 'Calendar'[Date] )
            <= CALCULATE (
                MAX ( Sales[Date] );
                FILTER (
                    ALL ( Sales );
                    AND (
                        RELATED ( 'Calendar'[MonthOffset] ) = -12;
                        RELATED ( 'Calendar'[DayNumber] ) <= CurrentDayNumber
                    )
                )
            );
        CALCULATE (
            [Total Sales];
            FILTER (
                FILTER (
                    ALL ( 'Calendar' );
                    AND (
                        'Calendar'[MonthOffset] = -12;
                        'Calendar'[DayNumber] <= CurrentDayNumber
                    )
                );
                'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
            )
        )
    )
MTD Running Total Sales = 
IF (
    MIN ( 'Calendar'[Date] )
        <= CALCULATE (
            MAX ( Sales[Date] );
            FILTER ( ALL ( Sales ); RELATED('Calendar'[MonthOffset]) = 0 )
        );
    CALCULATE (
        [Total Sales];
        FILTER (
            FILTER ( ALL ( 'Calendar' ); 'Calendar'[MonthOffset] = 0 );
            'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
        )
    )
)

 

When looking at the result through a Table, including Fiscal Year, Month Number and Day Number, everything seems to work just fine:

 

MeasuresOK.jpg

 

Now, when removing the Fiscal Year and the Month Number from the table, here's what I am expecting to get:

expected.jpg

But here's what I am getting:

 

result.jpg

 

This is driving me crazy as I have been stuck with this for quite some time and still cannot figure out what is wrong!!!

Any help would be greatly appreciated.

I can share a pbix file if necessary.

 

Thanks!

 

1 ACCEPTED SOLUTION

Correct formula

 

Prev MTD Running Total Sales =
VAR CurrentDayNumber =
    MIN ( MAX ( YTDInfos[CurrentDayNumber] ); MAX ( 'Calendar'[DayNumber] ) )
RETURN
    IF (
        [Prev MTD Sales] <> BLANK ();
        CALCULATE (
            [Total Sales];
            FILTER (
                ALL ( 'Calendar' );
                AND ( 'Calendar'[MonthOffset] = -12; 'Calendar'[DayNumber] <= CurrentDayNumber )
            )
        )
    )

View solution in original post

8 REPLIES 8
jlouvel
Frequent Visitor

The expected behavior is actually the following...

 

expected.jpg

 

Sorry for the inconvenience.

Hi @jlouvel,

 

Could you share a sample pbix file which can reproduce the issue, so that we can do some tests on it and better assist on this issue? You can upload it to OneDrive or Dropbox and post the link here. Do mask sensitive data before uploadingSmiley Happy

 

Regards

Below a link to a pbix file illustrating the problem.

 

RunningTotalProblemSample.pbix

 

Thanks.

Hello!
Try this formulas:

 

MTD Running Total Sales =
IF (
    [MTD Sales] <> BLANK ();
    CALCULATE (
        [Total Sales];
        FILTER (
            ALL ( 'Calendar' );
            'Calendar'[MonthOffset] = 0
                && 'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
        )
    )
)

 

 

Prev MTD Running Total Sales =
VAR CurrentDayNumber =
    MAX ( YTDInfos[CurrentDayNumber] )
RETURN
    IF (
        [Prev MTD Sales] <> BLANK ();
        CALCULATE (
            [Total Sales];
            FILTER (
                ALL ( 'Calendar' );
                AND ( 'Calendar'[MonthOffset] = -12; 'Calendar'[DayNumber] <= CurrentDayNumber )
            )
        )
    )

Sorry, Prev MTD Running Total Sales is not correct. I will post correct formula later

Correct formula

 

Prev MTD Running Total Sales =
VAR CurrentDayNumber =
    MIN ( MAX ( YTDInfos[CurrentDayNumber] ); MAX ( 'Calendar'[DayNumber] ) )
RETURN
    IF (
        [Prev MTD Sales] <> BLANK ();
        CALCULATE (
            [Total Sales];
            FILTER (
                ALL ( 'Calendar' );
                AND ( 'Calendar'[MonthOffset] = -12; 'Calendar'[DayNumber] <= CurrentDayNumber )
            )
        )
    )

jlouvel
Frequent Visitor

Thank you so much, this works beautifully!

 

Have a great day 🙂

Glad to help you.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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