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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
DavidDi
Frequent Visitor

Create line graph from four measure (X1/Y1) and (X2/Y2)

Dear all

I want to generate a base line for expected costs over a defined time period, based on project detail selected with a slicer.

 

I can calculate the start time and start cost, end time and final cost as measure. However, I do not know how to create a table from that to use this information to generate a line from start to end.

 

My starting point:

ProjektProjektdetailStartEndeGeplante Kosten
AA101.01.202127.12.2021 CHF                  1’000
AA201.01.202127.11.2021 CHF                  2’000
AA301.04.202126.01.2022 CHF                  3’000
AA401.09.202130.12.2021 CHF                  4’000
AA501.01.202227.12.2022 CHF                  5’000
AA601.05.202231.05.2022 CHF                  6’000
BB131.01.202125.02.2022 CHF                     500
BB231.01.202126.01.2022 CHF                  1’500
BB301.05.202127.03.2022 CHF                  2’500
BB401.10.202128.02.2022 CHF                  3’500
BB531.01.202225.02.2023 CHF                  4’500
BB631.05.202230.07.2022 CHF                  5’500
CC102.12.202027.11.2021 CHF                  2’000
CC202.12.202028.10.2021 CHF                  3’000
CC302.03.202127.12.2021 CHF                  4’000
CC402.08.202130.11.2021 CHF                  5’000
CC502.12.202127.11.2022 CHF                  6’000
CC601.04.202201.05.2022 CHF                  7’000

 

I have a slicer with project and project detail.

 

I also created four measures:

Start date:

 

 

Start = 
MINX(
	KEEPFILTERS(VALUES('Tabelle1'[Projektdetail])),
	CALCULATE(FIRSTDATE('Tabelle1'[Start]))
)

 

 

Start Cost - could be exchanged by a "0" column in the basis table.

 

 

Cost at Start = 0

 

 

End Date

 

 

Last date = 
MAXX(
	KEEPFILTERS(VALUES('Tabelle1'[Projektdetail])),
	CALCULATE(LASTDATE('Tabelle1'[Ende]))
)

 

 

And finally End cost:

 

 

Total Cost = 
CALCULATE(
	SUM('Tabelle1'[Geplante Kosten]),
	ALLSELECTED('Tabelle1'[Projektdetail])
)

 

 

 

And this works very well.

 

However, the final goal is to have a line from Start to end, depending on the project detail selected from the slicer.

How can I generate a line graph from here??

 

I am lost and I would appreciate support from the forum very much.

 

Best regards,

David

 

9 REPLIES 9
DavidDi
Frequent Visitor

Hi @v-zhangti  @lbendlin @Ashish_Mathur 

 

Please excuse me - I jumped into a possible solution, instead I should explain the underlying problem in a good way. I adjusted the files to the actual starting point and reduced the complexity.

 

I have two files with the following structure

1. Center file

ProjectProject DetailSales Recognition DatePlanned Cost 
AA127.12.2021 CHF                  1’000 
AA227.11.2021 CHF                  2’000 
BB125.02.2022 CHF                     500 
BB1a25.02.2022 CHF                  1’500Amendment

 

2. Actual Cost file

ProjectProject DetailBooking DateActual Cost
AA128.02.2021 CHF          200
AA128.05.2021 CHF          200
AA128.08.2021 CHF          400
AA128.10.2021 CHF          400
AA228.03.2021 CHF          500
AA228.05.2021 CHF          500
AA228.09.2021 CHF          800
AA228.12.2021 CHF          100
BB128.01.2021 CHF          100
BB128.02.2021 CHF          300
BB128.06.2021 CHF          300
BB128.08.2021 CHF          100
BB1a28.09.2021 CHF          400
BB1a28.12.2021 CHF          600
BB1a28.01.2022 CHF          200

 

To give some context:

Example project A: In project A there are different project stages, A1, A2....

Each stage has planned cost and a planned end date - sales recognition date. The start cost is always 0. The start date is calculated from the first time actual cost have been generated.

From a business perspective the target is to keep as close as possible to the resulting line "Start - End" with the running actual costs - then you are on track to keep the planned budget.


What I would like to achieve is to have a line graph with Actual Costs (Booking Date and Running Total for Actual COst) vs Ideal cost (Start/End Date, 0 Cost/Planned Cost).
It should then look like that, eg for Project A-A1:

DavidDi_0-1650134371223.png

This is my main goal. You select project and single project stage with a slicer. 

 

However, to make it a little bit more complicated:

If you realize that the planned budget is insufficient you may request an amendment. This should have the same end date, but a later start date.

To track this you would select two or even more project stages in the same project. If you do so it would be ideal to only display the earliest start date and sum of all planned cost at the (usually same) end date.

 

I have uploaded excel and PowerBi Files HERE .

I hope this helps to clarify my target.
Thanks,
David

Hi,

For a few selections of Project and Project Details, please show the the expected result in a Table format.  Once the result there appears correct, we can always transform the visual to a line chart.


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

Hi @Ashish_Mathur 

Your question helped to solve the first case - which is the most important.

I created the following table, and when you select A1 (or any other single "Project Detail" selection with the slicer, it works like a charm:

ProjectProject DetailDateCostCategory
AA128.02.2021 00:00200Actual
AA128.05.2021 00:00200Actual
AA128.08.2021 00:00400Actual
AA128.10.2021 00:00400Actual
AA228.03.2021 00:00500Actual
AA228.05.2021 00:00500Actual
AA228.09.2021 00:00800Actual
AA228.12.2021 00:00100Actual
BB128.01.2021 00:00100Actual
BB128.02.2021 00:00300Actual
BB128.06.2021 00:00300Actual
BB128.08.2021 00:00100Actual
BB1a28.09.2021 00:00400Actual
BB1a28.12.2021 00:00600Actual
BB1a28.01.2022 00:00200Actual
AA128.01.2021 00:000Base
AA228.02.2021 00:000Base
BB128.12.2020 00:000Base
BB1a28.08.2021 00:000Base
AA127.12.2021 00:001000Base
AA227.11.2021 00:002000Base
BB125.02.2022 00:00500Base
BB1a25.02.2022 00:001500Base

 

The pbix is still in the same location -  HERE .

The result in the dashborad looks as expected.

DavidDi_0-1650293162720.png

 

However, if I want to combine two project details, as it makes sense for B1 and B1a, the result is not satisfying (see below), since I only want to see the first start date and the last end date, displayed as red manual line:

DavidDi_1-1650293530059.png

Is it possible to create the running total with e.g. an IF-condition for the "Base"-Category, so that only the first and last date values are displayed?

Again - thank you already for helping me with the first case. I would appreciate it a lot if you or another participant could help me with the second case.

Best regards,

David

I think you are mixed up in the names.  I did not help you with any solution for the first part.


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

Hi,

On the X -axis, do you want to see Dates or Months?


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

Hi all
Hi @v-zhangti  @lbendlin 
I have uploaded excel and PowerBi Files HERE .
What I would like to achieve is to have a line graph with Actual Costs (Booking Date and Running Total for Actual COst) vs Ideal cost (Start/End Date, 0 Cost/Planned Cost).
It should then look like that, eg for Project A-A1:

DavidDi_0-1650051572239.png

 

I hope this helps to clarify my target.
Thanks,
David

v-zhangti
Community Support
Community Support

Hi, @DavidDi 

 

What kind of output do you expect in the end? For example, when Projekt selects A and Projektdetail selects A1, the X-axis of the line chart is the start time to the end time and the Y-axis is a straight line 1000?

vzhangti_0-1649864276112.png

Is this the output you expect? If not, please show the picture to show the result you expect.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

@DavidDi 

I don't think you want a line graph.

lbendlin_0-1649630946320.png

 

lbendlin_1-1649631023713.png

 

see attached for details.  One option is to generate data points between Start and Ende so that your chart gets filled. This option will result in too many data points if you go down to day level.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ldRdCoMwDADgq0ifh6RJW92jCmN3EO+ya+x6O8mqpi7GnzoRodB+NH/2vWnMzTQ2fsCW8UXAcYFVaTEtiu75KDaP/bzeAGCGGyO4h9hzBDVCjLgFCSziIUIacYzcE0KQDcdpxMtwUObk+CZeI4ERn86RXOwjQSBt3NVaPvdLrC8hc5PxMtLAjZHP61jhFUIyGq4w0DmCGuHiWFiQOhsNacTLcFCmhE4rvEKCrkdsE6jyFU5IF3d10+ggdwb83/UTghukFgnKd/2E0IzMBbk4xE4jjpFajk4mHK8RL8NZ/Qmudf2EpNFx6RzkR6dKyPAF", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Projekt = _t, Projektdetail = _t, Start = _t, Ende = _t, #"Geplante Kosten" = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Start", type date},{"Ende", type date},{"Geplante Kosten", Currency.Type}}, "de-CH"),
    #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Date", each List.Dates([Start],Number.From([Ende])-Number.From([Start])+1,#duration(1,0,0,0))),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date"),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}})
in
    #"Changed Type"

 

Another option is to only generate data points for Start and Ende.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ldRdCoMwDADgq0ifh6RJW92jCmN3EO+ya+x6O8mqpi7GnzoRodB+NH/2vWnMzTQ2fsCW8UXAcYFVaTEtiu75KDaP/bzeAGCGGyO4h9hzBDVCjLgFCSziIUIacYzcE0KQDcdpxMtwUObk+CZeI4ERn86RXOwjQSBt3NVaPvdLrC8hc5PxMtLAjZHP61jhFUIyGq4w0DmCGuHiWFiQOhsNacTLcFCmhE4rvEKCrkdsE6jyFU5IF3d10+ggdwb83/UTghukFgnKd/2E0IzMBbk4xE4jjpFajk4mHK8RL8NZ/Qmudf2EpNFx6RzkR6dKyPAF", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Projekt = _t, Projektdetail = _t, Start = _t, Ende = _t, #"Geplante Kosten" = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Start", type date},{"Ende", type date},{"Geplante Kosten", Currency.Type}}, "de-CH"),
     #"Renamed Columns" = Table.RenameColumns(Table.SelectColumns(#"Changed Type with Locale",{"Projekt", "Projektdetail", "Start", "Geplante Kosten"}),{{"Start", "Datum"}})
     & Table.RenameColumns(Table.SelectColumns(#"Changed Type with Locale",{"Projekt", "Projektdetail", "Ende", "Geplante Kosten"}),{{"Ende", "Datum"}})
in
    #"Renamed Columns"

 

But then you lose the ability to "stack" costs on top of each other.  Not sure how important that is.

 

See PBIX attached.

 

 

 

 

 

@lbendlin 
Thank you for the reply and this (I started two weeks ago with PowerBI) very impressive code.
Please give me some time to digest it - I will come back to you.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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