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
GaRaGe
New Member

Line Charts with Cumulative values

 I have my data like this (image below)

 

Capture.PNG

Now i need to create a line chart in Power BI. I am getting something like this (sample image below)

 

Capture.PNG

 

Just for illustration i used this chart (Target and Actuals are two lines). 

 

Now i need the lines to be cumulative over months. How can i do that in Power BI?

1 ACCEPTED SOLUTION
v-huizhn-msft
Employee
Employee

Hi @GaRaGe,

First, you should create a calculated column to get a number format month. If we use the Jan, Feb, Mar and so on. Month will order by alphabet.

Month! = SWITCH(Test[Month],"Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,"Jul",7,"Aug",8,"Sep",9,"Oct",10,"Nov",11,12)


1.PNG

Then create two measure for cumulative spend over month. 

Target = CALCULATE(SUM(Test[Spend]),FILTER(ALL(Test),Test[Month!]<=MAX(Test[Month!])&&Test[Metric]="Target"))

Actual = CALCULATE(SUM(Test[Spend]),FILTER(ALL(Test),Test[Month!]<=MAX(Test[Month!])&&Test[Metric]="Actual"))

Finally, create a line chart, select the [month!] field as axis, the two measures as value level.

2.PNG

Please feel free to ask if you any issue.

Best Regards,
Angelia

View solution in original post

26 REPLIES 26
mwinds
Helper I
Helper I

Hi all,

 

I've having issues with this measure. The line chart is cumulative for some months but not for others. Here's what I've got.

 

Actual Cumulative = CALCULATE(SUM(InvoiceDetails[Total LAD Funding]),FILTER(ALL('Date'),'Date'[Date]<=MAX(InvoiceDetails[Month invoiced])))

 

 

 

Budget Cumulative = CALCULATE(SUM(Spendperlot[Total]),FILTER(ALL('Date'),'Date'[Date]<=MAX(InvoiceDetails[Month invoiced])))

 

The figures are contained in separate tables and should include all of the values in those tables.

Chart looks like this.

mwinds_0-1662734403257.png

 

 I've set up a date table following this guide https://docs.microsoft.com/en-us/power-bi/guidance/model-date-tables and looks like this for example:

mwinds_1-1662734504382.png

 

Data in the Month Invoiced table looks like this 

mwinds_0-1662735615461.png

 

 

Has any one got ideas to why this isn't working properly?

Hi,

You should have a relationship (Many to One and Single) between the Month invoiced column and the Date column of the Date Table.  Ensure that the Month name column is sorted by the Month number column in the Date table.  To the X-axis of your visual, drag Year and Month name from the Date table.  Write these measures:

Actual Cumulative = CALCULATE(SUM(InvoiceDetails[Total LAD Funding]),datesbetween('Date'[Date],minx(all('Date'[Date]),'Date'[Date]),max('Date'[Date])))

Hope this helps.


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

Hi there, 

 

No luck im afriad. Chart looks like this 

mwinds_0-1662989461180.png

 

Here's the link to my file https://drive.google.com/file/d/1-litA5nfaKu4OPcpEVEGnKJG3E4sfA8E/view?usp=sharing 

 

Any help is appreciated. 

Hi,

Make the first relationship active.

Untitled.png


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

Super. Thanks. 

However the chart looks like this 

mwinds_0-1663151077648.png

The chart goes go up and seems to be ignoring every other month using continuous. 

Or looks like this if categorical shows every day individually.

mwinds_1-1663151199034.png

 

I'm looking for it to show every month on the x axis so the chart goes up gradually rather than in chunks.

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

Thanks so much for your help.

You are welcome.  If my previous reply helped, please mark that reply as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-huizhn-msft
Employee
Employee

Hi @GaRaGe,

First, you should create a calculated column to get a number format month. If we use the Jan, Feb, Mar and so on. Month will order by alphabet.

Month! = SWITCH(Test[Month],"Jan",1,"Feb",2,"Mar",3,"Apr",4,"May",5,"Jun",6,"Jul",7,"Aug",8,"Sep",9,"Oct",10,"Nov",11,12)


1.PNG

Then create two measure for cumulative spend over month. 

Target = CALCULATE(SUM(Test[Spend]),FILTER(ALL(Test),Test[Month!]<=MAX(Test[Month!])&&Test[Metric]="Target"))

Actual = CALCULATE(SUM(Test[Spend]),FILTER(ALL(Test),Test[Month!]<=MAX(Test[Month!])&&Test[Metric]="Actual"))

Finally, create a line chart, select the [month!] field as axis, the two measures as value level.

2.PNG

Please feel free to ask if you any issue.

Best Regards,
Angelia

Hi Angelia, 

 

Are you able to have a look to see where I'm going wrong with my measures? https://community.powerbi.com/t5/Desktop/Line-Charts-with-Cumulative-values/m-p/2758568/highlight/tr...

I have a question on the solution, I'm getting a cumalitive result fine, but I want it just for this year, as opposed to going as far back as the equivalent of the test[spend] table goes

If I date a Date filter, it still sums from the beginning of the table, as opposed to all results for the current year.

I know this is an old thread but i would like to ask a question on your solution. I have setup a measure to use COUNTA to total the number of tickets. I create a Matrix table and add Fiscal Year and Fiscal Period followed by adding the CountA measure. This is working as expected. I create a new measure see below that references the COUNTA measure to workout the cumulative totals for each Fiscal Period. I add this measure to the table and it is working as expected. Great.

 

IncidentCumulative = IF(COUNTROWS(Sheet1)>0,
CALCULATE(
[TotalTickets],
FILTER(ALLSELECTED(DIM_Date[Fiscal Period]),
DIM_Date[Fiscal Period] <=MAX (DIM_Date[Fiscal Period])
)
))
 
My issue comes down to the Line chart. I create a new Line chart add Month Name (Sorted by Fiscal Period) in the X-Axis and then add the cumulative measure in the Value. Fiscal Year is has also been added into the Legend field. The data is no cumulative, however if i change the X-Axis to Fiscal Period, same as you have done the line chart shows the cumulative values. How do i have a line chart that will show the cumulative values using Month Name in the X-Axis?

Hi,

Share some data and show the expected result in a simple table format.


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

The below image shows the values cumulating correctly but with the Fiscal Period on the X-Axis. Note the table is showing the correct details.

BlueMan_0-1600914269433.png

If i change the X-Axis to Month Name the Chart changes and is not cumulative.

 

BlueMan_1-1600914412471.png

Hi,

Share the link from where i can download your PBI file.


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

Hi, I have the same problem. If I send you the project could you help me?

Hi,

Share some data, describe the question and show the expected result.


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

First of all, thank you for your availability. Basically I have a graph that takes the costs of various locations of my company, I copy in a column only the costs of projects with ROI <2 years and then on the graph I can filter them by site (plant), by project phase (stage) and by date (the project completion dates are entered on the x axis). What I want to get is the cumulative value of the costs. Apparently the chart works well with these filters:

SinatraB_0-1659519552517.png

 

 

but when I select the filters differently, this happens:

SinatraB_1-1659519552521.png

 

What am I doing wrong? Thanks in advance.

Link to download the project: https://www.dropbox.com/s/txaqxv83llcjfp0/Test.pbix?dl=0

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

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.