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
askpbiuser
Helper I
Helper I

DAX considering previous rows result in next rows but same column

Hi All,

I have the below DAX summarized Table created using measures, which are returning right values till Sales column. I have to create another calculation say Right calc whose formula is to look at Min of Demand and Sales columns but considering the previous rows cumulative value of Right calc in the next subsequent rows. So the complexity is the cumulative sum of previous rows in the same calculation

I assumed its Min(Demand, Sales) in my Wrong calc calculation. However the calculation expected by business is what is mentioned in the Formula below. The Right Calc rightly displays the expected ouput as an example.I do have many categories, but for similicity I have taken one example.

askpbiuser_0-1714713303452.png


Could someone please help on creating the Right calc column/measure or guide me on how to do it ?

CategoryTypeDateDemandSalesWrong calcRight calcFormula
4090L16010-2-2024 00:00015600MIN(D2,E2)
4090L16031-5-2024 00:006555208208208MIN(D3-G2,E3)
4090L16025-11-2024 00:0015492609260926092MIN(D4-(G2+G3),E4)
4090L16030-12-2024 00:0015492888MIN(D5-(G2+G3+G4),E5)

 

3 REPLIES 3
v-tangjie-msft
Community Support
Community Support

Hi @askpbiuser ,

 

Thanks @TomMartens  for the quick reply.

 

DAX can not realize such recursive calculation, you can use EXCEL to create formulas to get the results and then import them into PBI Desktop as a data source.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

TomMartens
Super User
Super User

Hey @askpbiuser ,

 

I can not see a difference between Wrong and calcRight.

 

Nevertheless, you have to be aware of the fact that there is no implicit order of rows inside a table. This means that you have to use DAX windowing functions in combination with the partitionBy switch. Here you will find an introduction to WINDOW: WINDOW function (DAX) - DAX | Microsoft Learn

 

Hopefully, this helps to tackle your challenge.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Thanks Tom.
The difference between Wrong cal and Right calc formula is -
Wrong calc - MIN(Demand,Sales)
Right calc - MIN(Demand,Sales) for first row and then
MIN(Demand - (Sum of previous (Right calc result),Sales)
To note here is the MIN formula which keeps changing and takes cumulative total into consideration.
Please let me know if more information needed.
I still had no luck in getting the right ans.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.