Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hi!
I'm using Power Query and I need help creating a new column. I have a column called [Month / Year], which is a date column. It contains one row per month. Each row looks like this "1/1/2021, 2/1/2021, 3/1/2021, etc." I have another column called [Energy - Total]. It contains a decimal number. These decimal numbers are the total sum of hours for each month. For each row, I need to find the YEAR TO DATE sum.
So far the code I'm using below is providing a rolling SUM of all the [Energy - Total] column, but it's not resetting each year.
List.Sum(
List.FirstN(
#"Renamed Columns1"[#"Energy - Total"],
[Index]
)
)
Solved! Go to Solution.
Add [#"Month / Year"]<=Date
(Table,Date) =>
List.Sum(Table.SelectRows(Table, each Date.Year([#"Month / Year"])=Date.Year(Date) and [#"Month / Year"]<=Date)[#"Energy - Total"])
Stéphane
Hello, Stéphane! How can I modify the formula to add other column as reference?
I have to Sum YTD and by Location and can't figure out a way to add the second condition.
Add [#"Month / Year"]<=Date
(Table,Date) =>
List.Sum(Table.SelectRows(Table, each Date.Year([#"Month / Year"])=Date.Year(Date) and [#"Month / Year"]<=Date)[#"Energy - Total"])
Stéphane
You did it! That's amazing. Thanks very much.
Hi
...
Previous_Step = ...
Function_YTD = (Table,Date) =>
List.Sum(Table.SelectRows(Table, each Date.Year([#"Month / Year"])=Date.Year(Date))[#"Energy - Total"]),
YTD = Table.AddColumn(Previous_Step, "YTD", each Function_YTD(Previous_Step,[#"Month / Year"]))
...
Stéphane
Thank you so much for the reply. Is this how you intended to apply the code:
Unfortunately, while it's not providing an error, it's returning the same value for each row and not the YTD sum as of each month.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |