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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. 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
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.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

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.

Top Solution Authors