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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Writing Rows in a Calculated Table From Flat Data, and Building a Line Graph with the Results

Hi,

 

I'm new to writing dax in Power BI, and I have a need to convert hard data that looks like this into a monthly line graph going out from the task finish date to the number of months in the savings duration column. These are all hard columns from tables except the monthly savings, which is a calculated column (Savings / SavingsDuration).

 

IDTaskFinishDateSavingsSavingsDurationMonthly Savings
18-054/15/2019 5001241.67
18-025/1/2019322840.25
18-0271/1/20193001225
18-01087/1/2019220012183.33
18-00510/4/20191621213.50
18-0296/3/20191201120
18-02723/1/20196101610
18-02442/1/2019-51811-47.09

 

For example, the first savings row (projectidentifier 18-0599-00) starts April 15, 2019 and goes out 12 months with the monthly savings of $41,167 (5/15/2019, 6/15/2019, 7/15/2019, etc through 4/15/2020).

 

Each project ID could represent a seperate line, with a total line or something like it.

 

I've been at this several days attempting to create a calculated table that add rows based on the number of months in the SavingsDuration column, and then using the calculated table fields in visual, but I guess I just don't know dax well enough to get this done.

 

Any help on this, even helping me define the approach, would be greatly appreciated.

 

Thank  you in advance.

1 ACCEPTED SOLUTION
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous -

See if this gets you close to what you're going for:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc3RDcAgCATQXfi2wUNRO4tx/zUKJhZ/zOUeyJwESlQZypLxWtac7YXQSpPEC8axIl6MTcWnLrrXqsUeJnKjesxcj6JJYLPYuPwme3FT9yvxaUPQ8CNBj8IbGK4P", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ProjectID = _t, FinishDate = _t, Savings = _t, SavingsDuration = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ProjectID", Int64.Type}, {"FinishDate", type date}, {"Savings", Int64.Type}, {"SavingsDuration", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "AssignPeriods", each {1..[SavingsDuration]}),
    #"Expanded AssignPeriods" = Table.ExpandListColumn(#"Added Custom", "AssignPeriods"),
    #"Added Custom1" = Table.AddColumn(#"Expanded AssignPeriods", "Monthly Savings", each [Savings] / [SavingsDuration]),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom", each if [AssignPeriods] = 1 then [FinishDate] else Date.AddMonths([FinishDate],[AssignPeriods] - 1))
in
    #"Added Custom2"

Throw it into the Advanced Editor of a Blank Query.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

2 REPLIES 2
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous -

See if this gets you close to what you're going for:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc3RDcAgCATQXfi2wUNRO4tx/zUKJhZ/zOUeyJwESlQZypLxWtac7YXQSpPEC8axIl6MTcWnLrrXqsUeJnKjesxcj6JJYLPYuPwme3FT9yvxaUPQ8CNBj8IbGK4P", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ProjectID = _t, FinishDate = _t, Savings = _t, SavingsDuration = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ProjectID", Int64.Type}, {"FinishDate", type date}, {"Savings", Int64.Type}, {"SavingsDuration", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "AssignPeriods", each {1..[SavingsDuration]}),
    #"Expanded AssignPeriods" = Table.ExpandListColumn(#"Added Custom", "AssignPeriods"),
    #"Added Custom1" = Table.AddColumn(#"Expanded AssignPeriods", "Monthly Savings", each [Savings] / [SavingsDuration]),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom", each if [AssignPeriods] = 1 then [FinishDate] else Date.AddMonths([FinishDate],[AssignPeriods] - 1))
in
    #"Added Custom2"

Throw it into the Advanced Editor of a Blank Query.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Anonymous
Not applicable

This is exactly what I was trying to do - thank you so much 🙂

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors