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

Problem with Running total vizualisation

 Hi,

 

I am having a problem when graphically displaying my MTD running total sales.

I use the following Dax measure that I was able to come up with after reading the http://www.daxpatterns.com/cumulative-total article.

 

 

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] )
        )
    )
)

The Total Sales measure is just the explict measure for my Sales table (= SUM(Sales[Sales]))

 

My Calendar table provides offsets allowing me to easily create measure relative to the current date.

 

When displaying the result of my MTD Running Total Sales in a table, everything looks just fine, the values start and stop whenever they are supposed to:

 

MTDRunninTotalTable.jpg

Now, when displaying the same information using a line chart, using the Calendar[Date] on the X-Axis, everything looks just fine:

MTDRunningTotalLineChartWithDates.jpg

 

But when replacing the Dates with WeekNumbers (also coming from the Calendar table), here's what I get:

 

MTDRunningTotalLineChartWithWeekNumbers.jpg

So it is basically displaying the last value calulated by the measure for weeks not part of the scope of the calculation.

I am not sure where the problem stands as the table displays things correcty and so does the line chart only when using the dates.

Any help here would be greatly appreciated.

 

Thanks!

14 REPLIES 14
parry2k
Super User
Super User

I think your weeknumbers are across all the years and it is combining the data together for all the weeks from multiple years. if you add year and then week number and use drill down all level in hierarchary or create week number with year appended to it and then check.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Wah, that was quick!
Thank you so much, parry2k, adding the fiscal year did help in displaying the measure for the current fiscal year.

 

MTDRunningTotalLineChartWithYearAndWeekNumbers.jpg


But my objective is to display lines for both current and previous fiscal year for comparison purposes.
Having the year added does not really allow me to do this as I would get something more like this:

MTDRunningTotalLineChartWithYearAndWeekNumbersForBothYears.jpg

Which is not ideal...

Aha, drop week number on x axis and year on legend. that will do it.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

For some reason, I cannot drop Year on legend, it would not le me do it...

do you have more than one field in values? you have to have one field in values, can you send screen shot what kind of field you have on axis, value, legend?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I have 2 values (the 2 measures I want to compare)

- MTD Running Total Sales

- Prev MTD Running Total Sales

 

Here's a screenshot:

 

MTDRunningTotalLineChartWithYearAndWeekNumbersForBothYears2.jpg


 

 

I do something very similar in another visualization using another set of measures and a Area Chart and it works just fine, without having to add the year as a legend.

So I tend to think there is something wrong with my Running Total measures...

 

RevenueComparison.jpg

 

can you try to remove one value and atleast test it by using year in legend and then we can talk about what else is going on.

 

there is no way that you can have two values and legend that is for sure. based on your original post, you just gave the example with one value and all the discussion was around that



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

You are right, sorry, let's go step by step.

 

Having only one value and the year in legend is working as expected.

 

MTDRunningTotalLineChartYearInLegend.jpg

ok, atleast we are on same page, now what next? 🙂



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

So what I am trying to accomplish here is to have a chart line displaying the previous and current fiscal year running total sales over the same period of time.

And to do so, I have the 2 following measures (note that in my original post, the measures where MTD and prev MTD, but as we just switched to a new fiscal month, I have to use the YTD version to get more data to display)

 

 

YTD Running Total Sales = 
IF (
    MIN ( 'Calendar'[Date] )
        <= CALCULATE (
            MAX ( Sales[Date] );
            FILTER ( ALL ( Sales ); RELATED ( 'Calendar'[YearOffset] ) = 0 )
        );
    CALCULATE (
        [Total Sales];
        FILTER (
            FILTER ( ALL ( 'Calendar' ); 'Calendar'[YearOffset] = 0 );
            'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
        )
    )
)

 

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

When displaying those 2 measures in the same Line Chart using the week number on the X-Axis, here is what I get:

 

YTDRunningTotalsOverWeek_pb.jpg

 

 

 

When what I would like to get is more something like this:

 

wish.jpg

 

 

Meaning the weeks on the right side of the red line to be removed and the previous year to be displayed correctly (blue dotted line, instead of the black constant line).

 

I don't understand why the Chart line is displaying things like this when the same data displayed in a table looks perfect.

 

2017_Tab.jpg

 

2018_table.jpg

here is the thing, you cannot compare two values and also have legend. either you have to remove one value and use legend.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I have 2 values:

you cannot have two values if you want to use legend, remove one and then try with year in legend, also in that case you can remove year from x axis.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.