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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Substract two rows based on multiple conditions

Hello,

 

I need some help to substract two rows based on two conditons on Power BI. 

The first one is the name of the elctric meters ans the second the day and hour of meter readings.

JL8034_0-1672991914949.png

 

Thank you for your help.

Best regards

 

2 REPLIES 2
HiraNegi
Resolver II
Resolver II

Hi @Anonymous ,

 

I am assuming you want to substract only two rows (and not more) on the basis of two fields having same value.

 

You may use below method.

 

Sample Data:

HiraNegi_0-1672996686447.png

 

Steps:

1. Add an Index Column in Power Query.

HiraNegi_1-1672996755786.png

2. Create another column in DAX to get the Indexing partitoned by first two column like below.

GroupIndex =
CALCULATE(
COUNTROWS('Table (4)'),
FILTER('Table (4)', 'Table (4)'[C1] = EARLIER('Table (4)'[C1])),
FILTER('Table (4)', 'Table (4)'[DateTime] <= EARLIER('Table (4)'[DateTime])),
FILTER('Table (4)', 'Table (4)'[Index] <= EARLIER('Table (4)'[Index]))
)

HiraNegi_2-1672996864620.png

 

3. Add another column to find the MOD of index and multiply -1 with it so that it can be use for substraction.

ValueForSubstraction =
VAR vMOD = MOD('Table (4)'[GroupIndex],2)
Return
IF(vMOD = 0, 'Table (4)'[Value] * -1 , 'Table (4)'[Value])

HiraNegi_3-1672996977289.png

 

Now you can use this column in report to get the substracted value.

HiraNegi_4-1672997050663.png

Hope this helps.

 

Regards,

Hira Negi

 

 

ryan_mayu
Super User
Super User

@Anonymous 

is this based on line order, not the time?

could you pls the sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.