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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
eyewee
Frequent Visitor

Calculate Difference between 2 rows based on multiple column filters

I have the following table called filtered_POR050:
table.PNG
Here is the sample: link 

I would want to find the difference between hours (HEURE LIV) for each ID TOURNEE, filtered by date(JOUR LIV) and postal code (GroupeCP). If the previous value is absent, then the result should be 0.
Currently this is how the final result may look like.
rt.PNG

Please, can someone help me with it?

4 REPLIES 4
Anonymous
Not applicable

Hi @eyewee 

 

You can create a calculated column as follows.

 

DETLA = 
VAR _earlier = CALCULATE(MAX(filtered_POR050[Label_HEURE LIV]), FILTER(filtered_POR050, filtered_POR050[ID TOURNEE] = EARLIER(filtered_POR050[ID TOURNEE]) && filtered_POR050[JOUR LIV] = EARLIER(filtered_POR050[JOUR LIV]) && filtered_POR050[CP] = EARLIER(filtered_POR050[CP]) && filtered_POR050[Label_HEURE LIV] < EARLIER(filtered_POR050[Label_HEURE LIV])))
RETURN
IF(_earlier <> BLANK(), filtered_POR050[Label_HEURE LIV] - _earlier, 0)

 

 

vxuxinyimsft_0-1705374391138.png

Is this the result you expect?

 

Best Regards,
Community Support Team _Yuliax

 

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

Than you for your reply, your sotion does appear correct at first glance, but when I look into the Table View, I see the following:
wrong.PNG
The difference between these lines should be 0 instead of what is seen.

Also, could you please explain how does your dax expression work? How would I do if I wanted to display only the values that are equal or greater than 15 min (>=15) ? Or if I wanted to get a sum of these conditionned values per ID TOURNEE?

ryan_mayu
Super User
Super User

@eyewee 

what's the sequence of the data?

11.PNG

 

what if the time is earlier than the previous row?

 





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

Proud to be a Super User!




Thank you for your question, the data is presented in a strictly chronological order, thus, the two lines you've pointed on, do not belong to the same ID TOURNEE, when data is isolated by ID TOURNEE, CPgroupe and JOUR LIV, there will only be hours ranged in ascending order.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.