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
Anonymous
Not applicable

Actual vs Budget with Variable Start and End Dates

Hi All,

I am stuck on a rather buffling problem. I have measures the calculate actuals for different groups plotted on a line chart. What I would like to do is to add a budget line with a linear rate  for comparison purposes. I'll first show you what the budget data looks like:

SampleBUdgets.PNGIdeally, to have this data work with my model so far, I envision transforming this data to look like this:TransformedBudget.PNGI would appreciate any help with this problem! Thanks in advance.

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Anonymous here is example of M code which can get you wht you are looking for. Start new blank query and paste following code

 

Would appreciate Kudos 🙂 if my solution helped.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wci/KLy1QMFTSUTI0MjUAUkYGhpa6Bqa6BkYwjqGRrrGhUqwOTDFIwhym1kLX0EDXwBCu0QjEQag1BkkYmcClLZHNBWo0RVJrAnEEsrQhmhtiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Category = _t, Budget = _t, #"Start Date" = _t, #"End Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Budget", Int64.Type}, {"Start Date", type date}, {"End Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Days", each {0..1}),
    #"Expanded Days" = Table.ExpandListColumn(#"Added Custom", "Days"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Days", "New Budget", each if [Days]=0 then 0 else [Budget]),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Date", each if [Days]=0 then [Start Date] else [End Date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Budget", "Start Date", "End Date", "Days"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"New Budget", "Budget"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Budget", type number}, {"Date", type date}})
in
    #"Changed Type1"


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.

View solution in original post

2 REPLIES 2
parry2k
Super User
Super User

@Anonymous here is example of M code which can get you wht you are looking for. Start new blank query and paste following code

 

Would appreciate Kudos 🙂 if my solution helped.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wci/KLy1QMFTSUTI0MjUAUkYGhpa6Bqa6BkYwjqGRrrGhUqwOTDFIwhym1kLX0EDXwBCu0QjEQag1BkkYmcClLZHNBWo0RVJrAnEEsrQhmhtiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Category = _t, Budget = _t, #"Start Date" = _t, #"End Date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Budget", Int64.Type}, {"Start Date", type date}, {"End Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Days", each {0..1}),
    #"Expanded Days" = Table.ExpandListColumn(#"Added Custom", "Days"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Days", "New Budget", each if [Days]=0 then 0 else [Budget]),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Date", each if [Days]=0 then [Start Date] else [End Date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Budget", "Start Date", "End Date", "Days"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"New Budget", "Budget"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Budget", type number}, {"Date", type date}})
in
    #"Changed Type1"


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.

Anonymous
Not applicable

Hi @parry2k , thanks for the prompt assist. I did try it and it gave me the results I was look for so thank you! I did however find a cheeky work around using CROSSJOIN that made it a little more robust and easier to add trickery with DAX. Thanks again.

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.