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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
jgreutert
Regular Visitor

Calculation between rows

Hi Everybody,

I would like to make calculations between row. Es.

COD.    DESC.     VAL

     1           A          5

     2           B          3

     3           C    NULL

I would like to put in the third row the calculation 5-3=2

Can anyone help me, please?

Thank you in advance.

 

1 ACCEPTED SOLUTION

Hello,

I found the solution that I wanted. I post her in case can be useful for someonelse.

I created a misure VALUE BIS

VALUES BIS =

VAR CURRENT_ROW=SELECTEDVALUE(TABLE[ID])

VAR ROW3=CALCULATE(SUM(VALUE),FILTER(ALL(TABLE),TABLE[ID]=1))-CALCULATE(SUM(VALUE),FILTER(ALL(TABLE),TABLE[ID]=2))

RETURN
SWITCH(CURRENT_ROW,3,ROW3,SUM(VALUE))

 

Best regards

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@jgreutert , Try like. But logic is not extendable

maxx(filter(table,[COD] = earlier([COD]) -2),[VAL]) - maxx(filter(table,[COD] = earlier([COD]) -1),[VAL])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Is it possibile to do it as misure?

Many thanks for the useful answers!!

Hello,

I found the solution that I wanted. I post her in case can be useful for someonelse.

I created a misure VALUE BIS

VALUES BIS =

VAR CURRENT_ROW=SELECTEDVALUE(TABLE[ID])

VAR ROW3=CALCULATE(SUM(VALUE),FILTER(ALL(TABLE),TABLE[ID]=1))-CALCULATE(SUM(VALUE),FILTER(ALL(TABLE),TABLE[ID]=2))

RETURN
SWITCH(CURRENT_ROW,3,ROW3,SUM(VALUE))

 

Best regards

Greg_Deckler
Community Champion
Community Champion

@jgreutert - Not sure you can really do that (replace the NULL with some value) if this is in an actual table. You could create a new column. 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/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __Previous = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.