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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
AVS218
Frequent Visitor

Line and Histogram visualization of Avg. Price with mixed data structure coming from the CRM system

Is it possible to generate attached visualisation based on the data table. Some Projects are captured as single line Item and some are multiple line items

 

@mussaenda 

2021-07-31 08_46_34-Window.png

2021-07-31 08_46_42-Window.png

Project NameContract Start DateContract End DateContract Term (Years)Avg. Price per year
Project A31/03/202131/03/2026540000
Project B25/11/202124/11/2026542000
Project C25/04/202324/04/20242050000
Project C24/04/202424/04/20252051000
Project C24/04/202524/04/20262060000
Project C24/04/202624/04/20272060000
Project C24/04/202724/04/20282060000
Project C24/04/202824/04/20292060000
Project C24/04/202924/04/20302060000
Project C24/04/203024/04/20312060000
Project C24/04/203124/04/20322060000
Project C24/04/203224/04/20332060000
Project C24/04/203324/04/20342065000
Project C24/04/203424/04/20352065000
Project C24/04/203524/04/20362065000
Project C24/04/203624/04/20372065000
Project C24/04/203724/04/20382065000
Project C24/04/203824/04/20392066000
Project C24/04/203924/04/20402066000
Project C24/04/204024/04/20412067000
Project C24/04/204124/04/20422067000
Project C24/04/204224/04/20432067000
Project D31/03/202131/03/2026553000
Project E01/12/202101/12/20222075000
Project E01/12/202201/12/20232075000
Project E02/12/202101/12/20242075000
Project E01/12/202401/12/20252075000
Project E03/12/202101/12/20262075000
Project E01/12/202601/12/20272075000
Project E04/12/202101/12/20282075000
Project E01/12/202801/12/20292075000
Project E05/12/202101/12/20302075000
Project E01/12/203001/12/20312075000
Project E06/12/202101/12/20322075000
Project E01/12/203201/12/20332075000
Project E07/12/202101/12/20342075000
Project E01/12/203401/12/20352075000
Project E08/12/202101/12/20362075000
Project E01/12/203601/12/20372075000
Project E09/12/202101/12/20382075000
Project E01/12/203801/12/20392075000
Project E10/12/202101/12/20402075000
Project E01/12/204001/12/20412075000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
Project F01/12/202101/12/20412059000
1 ACCEPTED SOLUTION

Hi @AVS218,

 

mussaenda_0-1627811510706.png

 

According to your reply, Project A will refrlect 5 times from year 1 to year 5.

But from your expected output, it is reflected from year 1 to year n. This is where I am confused.

 

Anyhow, I hope this helps you. I think others can still improve my query, but hope that my idea will help you.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7ZQ9a8MwFEX/SvEcsKT79OGxTdO5e8hUunQplP5/ate1fLEV6e21wcMxOtwQDrpeu9evz4/3t++Hx+7UwfYGvTPOMoQR/PiKGZ/udlqdp/Gr8721i+PkD7Ljts55doxMxzA7M8gEZhJ3Q+fduQV8lmxV8gxhkUJ9KTBEpRQZklJKDINSGghgdNJ8bgGrlCyDU0qOAUqJi0AuIviqxEXAKyUuAkEpcRGISomLQFJKXATWIkJV4iLE6CThImQtIlYlLkKcUuIiBPel5+Zd5LF1LuNXY3vrFidD/nVx949ftucyoCG50pIol4TBNySUloJyKTDEhiSlpaRcSgxDQ/KFpfUGqy/9nstgG1IoLSmLABeBVhGxtKQsAlwEWkWk0pKyCHARaBUxlJaURYCLQKMIawpLoixCuAipFPFy745YJT8c0iEd0v+Sbj8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project Name" = _t, #"Contract Start Date" = _t, #"Contract End Date" = _t, #"Contract Term (Years)" = _t, #"Avg. Price per year" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Name", type text}, {"Contract Start Date", type date}, {"Contract End Date", type date}, {"Contract Term (Years)", Int64.Type}, {"Avg. Price per year", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Project Name", Order.Ascending}, {"Contract Start Date", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Project Name"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"all", each _, type table [Project Name=nullable text, Contract Start Date=nullable date, Contract End Date=nullable date, #"Contract Term (Years)"=nullable number, Avg. Price per year=nullable number, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([all], "Index Per Project", 1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Index Per Project"}, {"Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Index Per Project"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Count] = 1 
then {1..[#"Contract Term (Years)"]}
else {[Index Per Project]}),
    #"Expanded Custom1" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
    #"Added Custom2" = Table.AddColumn(#"Expanded Custom1", "Contract Year", each if [Custom]> 10
then "Year n"
else 

"Year " & Number.ToText([Custom])),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"Project Name", "Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Custom", "Contract Year"}),
    #"Added Custom3" = Table.AddColumn(#"Removed Other Columns", "Contract Year Index", each if [Contract Year] = "Year n"
and [Contract Year] = "Year n"
then 11 else 

[Custom]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom3",{{"Contract Start Date", type date}, {"Contract End Date", type date}, {"Contract Term (Years)", Int64.Type}, {"Avg. Price per year", Int64.Type}, {"Custom", Int64.Type}, {"Contract Year", type text}, {"Contract Year Index", Int64.Type}})
in
    #"Changed Type1"

 

 

View solution in original post

7 REPLIES 7
mussaenda
Super User
Super User

Hi @AVS218 , 

 

mussaenda_0-1627796226530.png

 

How come that your Project A and Project B has value on the expected output you provided but on the data you provided, the contract is only 5 years? 

 

Same with Project D.

 

Am I missing something?

 

Thanks

 

 

@mussaenda ...That's how data is captured in CRM system. Some projects are recorded as single line item and some as multiple line because of staggered prices... We need to have visualisation which takes into consideration both scenarios and project expected revenue every year.

Hi @AVS218,

 

let me be clear, 

if the contract year is less than 20 or if the row is single for the project, then I will project the price? Price projected is the last price?

 

Thanks

Yes if project is captured single line we project price for number of year's shown i.e. For Project A I'll show €40k 5 times or year 2021 to 2026... For project C I'll use price shown in respective year

Hi @AVS218,

 

mussaenda_0-1627811510706.png

 

According to your reply, Project A will refrlect 5 times from year 1 to year 5.

But from your expected output, it is reflected from year 1 to year n. This is where I am confused.

 

Anyhow, I hope this helps you. I think others can still improve my query, but hope that my idea will help you.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7ZQ9a8MwFEX/SvEcsKT79OGxTdO5e8hUunQplP5/ate1fLEV6e21wcMxOtwQDrpeu9evz4/3t++Hx+7UwfYGvTPOMoQR/PiKGZ/udlqdp/Gr8721i+PkD7Ljts55doxMxzA7M8gEZhJ3Q+fduQV8lmxV8gxhkUJ9KTBEpRQZklJKDINSGghgdNJ8bgGrlCyDU0qOAUqJi0AuIviqxEXAKyUuAkEpcRGISomLQFJKXATWIkJV4iLE6CThImQtIlYlLkKcUuIiBPel5+Zd5LF1LuNXY3vrFidD/nVx949ftucyoCG50pIol4TBNySUloJyKTDEhiSlpaRcSgxDQ/KFpfUGqy/9nstgG1IoLSmLABeBVhGxtKQsAlwEWkWk0pKyCHARaBUxlJaURYCLQKMIawpLoixCuAipFPFy745YJT8c0iEd0v+Sbj8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project Name" = _t, #"Contract Start Date" = _t, #"Contract End Date" = _t, #"Contract Term (Years)" = _t, #"Avg. Price per year" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Name", type text}, {"Contract Start Date", type date}, {"Contract End Date", type date}, {"Contract Term (Years)", Int64.Type}, {"Avg. Price per year", Int64.Type}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Project Name", Order.Ascending}, {"Contract Start Date", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Project Name"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"all", each _, type table [Project Name=nullable text, Contract Start Date=nullable date, Contract End Date=nullable date, #"Contract Term (Years)"=nullable number, Avg. Price per year=nullable number, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([all], "Index Per Project", 1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Index Per Project"}, {"Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Index Per Project"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Count] = 1 
then {1..[#"Contract Term (Years)"]}
else {[Index Per Project]}),
    #"Expanded Custom1" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
    #"Added Custom2" = Table.AddColumn(#"Expanded Custom1", "Contract Year", each if [Custom]> 10
then "Year n"
else 

"Year " & Number.ToText([Custom])),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"Project Name", "Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Custom", "Contract Year"}),
    #"Added Custom3" = Table.AddColumn(#"Removed Other Columns", "Contract Year Index", each if [Contract Year] = "Year n"
and [Contract Year] = "Year n"
then 11 else 

[Custom]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom3",{{"Contract Start Date", type date}, {"Contract End Date", type date}, {"Contract Term (Years)", Int64.Type}, {"Avg. Price per year", Int64.Type}, {"Custom", Int64.Type}, {"Contract Year", type text}, {"Contract Year Index", Int64.Type}})
in
    #"Changed Type1"

 

 

AVS218_0-1628415069468.png

@mussaenda Thanks for your help so far. Was able to crack first solution which is in top graph. For Bottom one I'm struggling how you will achieve breakdown by year for Project A,B, D & F

 

I added custom column with Date.AddYear function but now landed with nested list in which I can see all values I'm seeking but not able to extract all of them. Not sure whether this is right approach to support in get right line graph for Projects A,B,D & F. Any recommendation @Greg_Deckler  / @mussaenda  / @Anonymous / @amitchandak 

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7ZQ9a8MwFEX/SvEcsKT79OGxTdO5e8hUunQplP5/ate1fLEV6e21wcMxOtwQDrpeu9evz4/3t++Hx+7UwfYGvTPOMoQR/PiKGZ/udlqdp/Gr8721i+PkD7Ljts55doxMxzA7M8gEZhJ3Q+fduQV8lmxV8gxhkUJ9KTBEpRQZklJKDINSGghgdNJ8bgGrlCyDU0qOAUqJi0AuIviqxEXAKyUuAkEpcRGISomLQFJKXATWIkJV4iLE6CThImQtIlYlLkKcUuIiBPel5+Zd5LF1LuNXY3vrFidD/nVx949ftucyoCG50pIol4TBNySUloJyKTDEhiSlpaRcSgxDQ/KFpfUGqy/9nstgG1IoLSmLABeBVhGxtKQsAlwEWkWk0pKyCHARaBUxlJaURYCLQKMIawpLoixCuAipFPFy745YJT8c0iEd0v+Sbj8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Project Name" = _t, #"Contract Start Date" = _t, #"Contract End Date" = _t, #"Contract Term (Years)" = _t, #"Avg. Price per year" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project Name", type text}, {"Contract Start Date", type date}, {"Contract End Date", type date}, {"Contract Term (Years)", Int64.Type}, {"Avg. Price per year", Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"Project Name", Order.Ascending}, {"Contract Start Date", Order.Ascending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
#"Grouped Rows" = Table.Group(#"Added Index", {"Project Name"}, {{"Count", each Table.RowCount(_), Int64.Type}, {"all", each _, type table [Project Name=nullable text, Contract Start Date=nullable date, Contract End Date=nullable date, #"Contract Term (Years)"=nullable number, Avg. Price per year=nullable number, Index=number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([all], "Index Per Project", 1)),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Index Per Project"}, {"Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Index Per Project"}),
#"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Count] = 1
then {1..[#"Contract Term (Years)"]}
else {[Index Per Project]}),
#"Expanded Custom1" = Table.ExpandListColumn(#"Added Custom1", "Custom"),
#"Added Custom2" = Table.AddColumn(#"Expanded Custom1", "Contract Year", each "Year " & Number.ToText([Custom])),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"Project Name", "Count", "Contract Start Date", "Contract End Date", "Contract Term (Years)", "Avg. Price per year", "Custom", "Contract Year"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Avg. Price per year", type number}, {"Contract Start Date", type date}, {"Contract End Date", type date}, {"Contract Term (Years)", Int64.Type}, {"Custom", Int64.Type}, {"Contract Year", type text}, {"Count", Int64.Type}}),
#"Start Year (Nested)" = Table.AddColumn(#"Changed Type1", "Start Year", each if [Count] = 1 then {if [Custom] = 1 then {[Contract Start Date]} else {Date.AddYears([Contract Start Date],[Custom]-1)}} else {[Contract Start Date]})
in
#"Start Year (Nested)"

Greg_Deckler
Community Champion
Community Champion

@AVS218 So, yes, you are going to need something like the following if I am understanding the ask:


Take a look at these two Quick Measures as I think you want something like them.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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