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
Anonymous
Not applicable

Maximum difference between two tables

Hi all,

I have two tables, ones containing measured values by some sensorsand one containing estimated values for those locations.  Both tables contain results for a 24hours duration. Each table have the following relevant columns:

- Sensor ID

- Hour

- Value measured/calculated

- Auxiliar ID which concatenate the sensor ID with the hour , which allows to stablish a relationship between the two tables to compare results for each timestep

 

For each sensor, I wanted a table that showed the maximum difference between calculated and measured values so I can see in which sensors my predicted values are off. I used the following DAX:

 

MDiff = maxx(RELATEDTABLE(Calculated Values),(MAXX(Merge1,abs(Merge1[Measured value] - ModelResults[Calculated Value]))))
 
The problem I have is that it seems to ignore the Sensor context (see images below) and it seems to compare against every sensor. I know potentially I could create a joined table using PowerQuery but I was wondering whether I could implement the calculation using DAX.
 

Many thanks,

Capture.PNGCapture1.PNGCapture2.PNG

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

@Anonymous 

try smth like

CALCULATE(
MAXX(Merge1,abs(Merge1[Measured value] - ModelResults[Calculated Value])),
ALLEXCEPT(Merge1, Merge1[Sensor ID])
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

While it would be better to append your table (with predicted/measured with same column name), and pivot that column out to get predicted and measured on same rows, please try this approach as a Measure instead of a calculated column.

 

Max Difference = MAXX(MeasuredTable, MeasuredTable[MeasuredValue] - RELATED(PredictedTable[PredictedValue]))

 

This assumes there is a 1:1 relationship (or Many:1) between the Measured and Predicted tables.  Use the measure in a table visual with your SensorID column from the MeasuredTable.  You could also use the measure in a line chart to visualize the different at each hour.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks Mahoneypat, but it seems the related function does not accept any column from my related table

az38
Community Champion
Community Champion

@Anonymous 

try smth like

CALCULATE(
MAXX(Merge1,abs(Merge1[Measured value] - ModelResults[Calculated Value])),
ALLEXCEPT(Merge1, Merge1[Sensor ID])
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors