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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
f1rich
Frequent Visitor

City from Date and ID

Hi guys,

 

Hope you can help me here..... I have been looking in google to find a dax formula with no luck.

What i am trying to do is create a dax column for my visual table to show the city from the lowest Date for each ID - see example below

Is this possible?

 

IDDateCityColumn
5555501/01/20 10:34:36LeedsLeeds
5555501/01/20 10:35:02SheffieldLeeds
6666602/01/20 00:12:40BristolBristol
6666602/01/20 00:12: 45BradfordBristol
6666602/01/20 00:12:57BradfordBristol
1 ACCEPTED SOLUTION
stevedep
Memorable Member
Memorable Member

Hi,

 

This should do the trick:

 

___firstCity = 
var _firstDate = CALCULATE(MIN([Date]), ALLEXCEPT('Table','Table'[ID]))
return
CALCULATE(MIN('Table'[City]), FILTER(ALLEXCEPT('Table','Table'[ID]),[Date]=_firstDate))

 

as seen here:

firstcity.png

As demonstrated here

the file available here

 

Please mark as a solution if so. Thumbs up for the effort are appreciated.

 

Kind regards,

 

Steve. 

View solution in original post

5 REPLIES 5
stevedep
Memorable Member
Memorable Member

Hi,

 

This should do the trick:

 

___firstCity = 
var _firstDate = CALCULATE(MIN([Date]), ALLEXCEPT('Table','Table'[ID]))
return
CALCULATE(MIN('Table'[City]), FILTER(ALLEXCEPT('Table','Table'[ID]),[Date]=_firstDate))

 

as seen here:

firstcity.png

As demonstrated here

the file available here

 

Please mark as a solution if so. Thumbs up for the effort are appreciated.

 

Kind regards,

 

Steve. 

Thank you so much @stevedep ! 😀

I have been trying to do this for 2 days 😱

Welcome! Keep learning, it gets more easy over time. 

camargos88
Community Champion
Community Champion

Hi @f1rich ,

 

Try this measure:

 

NewColumn = 
VAR _minDate = CALCULATE(MIN([Date]), ALLEXCEPT('Table', 'Table'[D]))
VAR _minCity = CALCULATE(MAX('Table'[City]), FILTER(ALLEXCEPT('Table', 'Table'[D]), [Date] = _minDate))
RETURN _minCity

 

Capture.PNG

 



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

Proud to be a Super User!



Morning @camargos88 

 

Unfortunately the fomula is not working because it is picking the last letter from City not from the date and ID - see example below

 

IDDateCityColumn
7777705/01/2020 20:36:22RotherhamSheffield
7777705/01/2020 20:36:25Sheffield

Sheffield

 

What I need is to show the first city from the earliest date from the same ID - see below

 

IDDateCityColumn
6666605/01/2020 19:02:03BarnsleyBarnsley
6666605/01/2020 19:02:06CudworthBarnsley
7777705/01/2020 20:36:22RotherhamRotherham
7777705/01/2020 20:36:25SheffieldRotherham
8888805/01/2020 21:04:34BristolBristol

 

Thank you

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.