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

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

Reply
bhmiller89
Helper V
Helper V

Using MAX Function Across two columns

I have parking lot occupancy data and the data is captured multiple times a day. I want to see the most recent data. I created a column, "LastSampleDate" To show the most recent date/time a sample was captured. However, I can't figure out how to show the #Occupied Spaces. Example: the "Brooke" location had occupied spaces samples throughout the day but at the last sampling, 8:42:25PM, there were only 140 spaces occupied but the data is summing everything for the whole day

 

sample1.JPGsample2.JPG

 

1 ACCEPTED SOLUTION

Hi,

 

In the visualisation pane, click on the roller brush icon and under Totals, turn off the Totals.  Now drag the measure in the visual.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

12 REPLIES 12
Pulkit
Resolver I
Resolver I

Choose the latest() function for the datetime column, this will give you only the latest result for each location.
Ashish_Mathur
Super User
Super User

Hi,

 

You do not need a Lastsampledate column in your dataset.  Try these measures

 

Last Sample Date = MAX(Data[DSample])

Occupied spaces on last sample date = LOOKUPVALUE(Data[OccupiedSpaces],Data[DSample],[Last Sample Date],Data[Location],Data[Location])

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur the only issue is it won't work for each location, the measure only seems to work if I type in a location.  There are 4 locations total, I was just using "Brooke" as an example. This is what works but how do I make it work for all locations?

 

LastOccupiedSpaces = LOOKUPVALUE(ParkingLotSample[OccupiedSpaces], ParkingLotSample[DSample], [LastSampleD], ParkingLot[Location], "Brooke")

Why are you hard coding Brooke in the DAX formula.  I have not done that in mine.  Try this

 

=LastOccupiedSpaces = LOOKUPVALUE(ParkingLotSample[OccupiedSpaces], ParkingLotSample[DSample], [LastSampleD], ParkingLot[Location],ParkingLot[Location])


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur it won't allow me to do it that way

 

capture3.JPG

Hi,

 

Try this

 

=LastOccupiedSpaces = LOOKUPVALUE(ParkingLotSample[OccupiedSpaces], ParkingLotSample[DSample], [LastSampleD], ParkingLot[Location],VALUES(ParkingLot[Location]))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

It didn't like that either It returned 

 

"Couldnl't Load the data for this visual

 

MdxScript(Model) (7,156) Calculation error in measure 'ParkingLotSample'[LastOccupiedSpaced]: A table of multiple values was supplied where a single value was expected"

 

 

 

Hi,

 

Share the link from where i can download the file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

 

I received absolutely no error.  I just ticked the box for LastOccupiedSpaces.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Ugh it still won't work for me! I don't know why. Thanks for all of your help!

Hi,

 

In the visualisation pane, click on the roller brush icon and under Totals, turn off the Totals.  Now drag the measure in the visual.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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