Forum Discussion
Add Multiple Columns from List that Have Standard Mathematical Operation
msmays5 Not sure if easier or harder, but definitely pretty simple in DAX. But, I know that ImkeF has solved this and probably edhans has as well. I'm sure they will be along shortly or maybe HotChilli , quite a few good Power Query people on the boards.
Just for reference (FYI only), one DAX method is the MTBF pattern. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column =
VAR __Current = [Value]
VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])
VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
__Current - __Previous
Here's some code to make the provided algorithm work:
#"Added Index" = Table.AddIndexColumn(#"Expanded P2", "Index", 0, 1, Int64.Type),
AccumulateFacts =
List.Accumulate(ListOfFacts, #"Added Index",
(state, current) => Table.AddColumn(state, current & " Chg", each Number.FromText(Table.Column(#"Added Index", current & " P1"){[Index]}) - Number.FromText(Table.Column(#"Added Index", current & " P2"){[Index]})
)
)
I added an Index to get a quick way of identifying the row. Pretty sure the code can be made to work without it but I'll leave that as an exercise.
Also, the code provided by the OP didn't pass syntax check.
- msmays55 years agoHelper II
HotChilli @Thanks for the reply, and sorry for the delayed response. I'm actually not sure if it worked because I received a PQ error saying I ran out of memory (before that step, PQ said it was loading 88 MB). Any ideas why that happens?
- HotChilli5 years agoCommunity Champion
I hope that you test your algorithms with small, representative datasets before testing on your real data.
You have options (make sure you have 64 bit powerbi -it would be unusual not to but I thought I'd mention it)
Make sure you have enough memory. Power Query will try and use all the memory it needs for complex operations, it's like climbing up the mountain. Once it's over the top, happy days.
Re-write the algorithm to avoid the problem. This may be easier said than done but there's always another way to do it..
Edit: What's your data source?