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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Astral
New Member

Monthly stock increase and delta

Hello, I am looking for how to calculate the monthly difference as well as the delta or percentage of monthly increase or decrease, in terms of an inventory of items, in excel I have to place the formula manually, I consider that power bi can do it only by selecting the months to compare.
imagen ejemplo.JPG
I appreciate a lot for yo

 

1 ACCEPTED SOLUTION

Here is a good paragraph on this issue I found on the web:

https://www.reddit.com/r/PowerBI/comments/9m0b49/dax_refer_to_previous_row_of_same_column/

Alternatively, and arguably a better approach, you may use Power Query before your data hits the DAX engine. Power Query bypasses the issue with DAX (discussed in the next two paragraphs) in multiple ways - the most elegant (although advanced - there's simpler methods) would List.Accumulate().

However, and every other post missed this, the answer to "Is it possible to have a Calculated DAX column that uses the previous rows calculated value as an input? " is NO. This is a recursive question. DAX cannot do recursion.

The reason why is simple: when the engine is compiling your calculated columns the smallest atomic unit in the DAX engine is a column - not a cell, like Excel. DAX cannot calculate the first cell in a column, then the next, then the next etc because it has no concept of a cell. It calculates the entire column at once because there is nothing smaller. This is a very important concept to understand when first learning DAX.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


View solution in original post

4 REPLIES 4
kentyler
Solution Sage
Solution Sage

think about unpivoting your data to look more like this

CategoriaMescantidaddifferencia * mesdelta
DesktopsEnero10  
DesktopsFebrero4-640.00%
DesktopsMarzo1511375.00%
DesktopsAbril9-660.00%
LaptopsEnero3021333.33%
LaptopsFebrero12-1840.00%
LaptopsMarzo153125.00%
LaptopsAbril4530300.00%

the calculations that involve comparison with the "preceding row" are much easier to do in excel than in power bi. You can do them there but it involves writing a lot of dax code. Do the calculation before you load the data and user power bi to create your reports





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Thank you Kentyler for your guidance.

 

Regards

Here is a good paragraph on this issue I found on the web:

https://www.reddit.com/r/PowerBI/comments/9m0b49/dax_refer_to_previous_row_of_same_column/

Alternatively, and arguably a better approach, you may use Power Query before your data hits the DAX engine. Power Query bypasses the issue with DAX (discussed in the next two paragraphs) in multiple ways - the most elegant (although advanced - there's simpler methods) would List.Accumulate().

However, and every other post missed this, the answer to "Is it possible to have a Calculated DAX column that uses the previous rows calculated value as an input? " is NO. This is a recursive question. DAX cannot do recursion.

The reason why is simple: when the engine is compiling your calculated columns the smallest atomic unit in the DAX engine is a column - not a cell, like Excel. DAX cannot calculate the first cell in a column, then the next, then the next etc because it has no concept of a cell. It calculates the entire column at once because there is nothing smaller. This is a very important concept to understand when first learning DAX.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Really helpfull information, I´ll taka as solution to use power Query, too advanced for me but ill try it. 🙂

 

Regards

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.