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
Saxon10
Post Prodigy
Post Prodigy

Calculate Max date by filter two columns

Saxon10_0-1617619969048.png

 

I have a two tables are data and report

    

In data table contain item, country, date, time and area code

    

In data table country column has India, Pak, US, UK, AUS, SRI, CAND and NEWL.

    

In report table contain item only (item as a duplicated)

    

I am looking for max date based on the following criteria: 1. Max time 2. Country is {India,US,UK,NEWL} and rest of the country code need to be ignore 3. area code {A} only.

    

If items is exist then return max date based on the max time column and filter by certain of country {India,US,UK,NEWL} and area code is {A} only.

    

Each item must be has 4 Country {India,US,UK,NEWL} if not then return blanks (Example -30123 ,3333)

    
DATA TABLE
ITEMCOUNTRYDATETIMEAREA CODE
123INDIA02/04/202123:15:00A
123PAK02/04/202123:15:00A
123US02/04/202123:15:00A
123UK02/04/202123:15:00A
123AUS02/04/202123:15:00A
123SRI02/04/202123:15:00A
123CAND02/04/202123:15:00A
123NEWL02/04/202123:15:00A
123INDIA23/03/202123:15:00A
123PAK23/03/202123:15:00A
123US23/03/202123:15:00A
123UK23/03/202123:15:00A
123AUS23/03/202123:15:00A
123SRI23/03/202123:15:00A
123CAND23/03/202123:15:00A
123NEWL23/03/202123:15:00A
123 23/03/202123:10:00B
1235INDIA02/04/202123:15:00A
1235NEWL02/04/202123:15:00A
1235US02/04/202123:15:00A
1235UK02/04/202123:15:00A
1235INDIA28/03/202123:15:00A
1235AUS28/03/202123:15:00A
1235US28/03/202123:15:00A
1235UK28/03/202123:15:00A
6789INDIA05/04/202123:15:00A
6789PAK05/04/202123:15:00A
6789US05/04/202123:15:00A
6789UK05/04/202123:15:00A
6789AUS05/04/202123:15:00A
6789SRI05/04/202123:15:00A
6789CAND05/04/202123:15:00A
6789NEWL05/04/202123:15:00A
4342INDIA03/04/202123:15:00A
4342NEWL03/04/202123:15:00A
4342US03/04/202123:15:00A
4342UK03/04/202123:15:00A
1237INDIA04/04/202110:19:00A
1237PAK04/04/202110:19:00A
1237US04/04/202110:19:00A
1237UK04/04/202110:19:00A
1237AUS04/04/202110:19:00A
1237SRI04/04/202110:19:00A
1237CAND04/04/202110:19:00A
1237NEWL04/04/202110:19:00A
1237 02/04/202110:16:00B
30123INDIA02/04/202123:15:00A
30123US02/04/202123:15:00A
30123 02/04/202123:15:00B
3333INDIA02/04/202123:15:00A
3333NEWL02/04/202123:15:00A
3333 02/04/202123:15:00B
     

 

REPORT TABLE
ITEMMAX DATE(DESIRED RESULT)
12302/04/2021
1234502/04/2021
30123 
123502/04/2021
678905/04/2021
434203/04/2021
3333 
1 ACCEPTED SOLUTION

Hi, @Saxon10 

Please check the below-updated link that includes the calculated column.

 

https://www.dropbox.com/s/hjra12fkfkixrvl/saxon10.pbix?dl=0 

 

Max Date new column =
VAR countriescondition =
SUMMARIZE ( FILTER ( Data, Data[ITEM] = Report[ITEM] ), Data[COUNTRY] )
VAR newtable =
FILTER (
Data,
Data[ITEM] = Report[ITEM]
&& Data[COUNTRY]
IN { "INDIA", "US", "UK", "NEWL" }
&& Data[AREA CODE] IN { "A" }
)
RETURN
IF (
COUNTROWS ( countriescondition ) >= 4,
MAXX ( newtable, Data[DATE] ),
BLANK ()
)

 

If you write calculated measure, the table visualization already has the filter for the item, so I did not mention the item column in the calculated measure.

However, as you can see in the calculated column, I had to mention the item column.

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi, @Saxon10 

Please check the below measure and the sample pbix file's link whether it is what you are looking for.

 

https://www.dropbox.com/s/hjra12fkfkixrvl/saxon10.pbix?dl=0 

 

Max Date =
VAR countriescondition =
VALUES ( Data[COUNTRY] )
VAR newtable =
FILTER (
Data,
Data[COUNTRY]
IN { "INDIA", "US", "UK", "NEWL" }
&& Data[AREA CODE] IN { "A" }
)
RETURN
IF ( COUNTROWS ( countriescondition ) >= 4, MAXX ( newtable, Data[DATE] ), "" )

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi,

 

Thanks for your reply.

 

Your solution working well. I would like to get the same result by using New calculated column.

 

 

Can you please advise me why the item column not mentioned in your measure? How it pick actual result without item column range?

 

Herewith attached the PBI file for your reference. (Data and report file)

 

https://www.dropbox.com/s/prtdxmt7whfr8kc/saxon10.pbix?dl=0

 

Hi, @Saxon10 

Please check the below-updated link that includes the calculated column.

 

https://www.dropbox.com/s/hjra12fkfkixrvl/saxon10.pbix?dl=0 

 

Max Date new column =
VAR countriescondition =
SUMMARIZE ( FILTER ( Data, Data[ITEM] = Report[ITEM] ), Data[COUNTRY] )
VAR newtable =
FILTER (
Data,
Data[ITEM] = Report[ITEM]
&& Data[COUNTRY]
IN { "INDIA", "US", "UK", "NEWL" }
&& Data[AREA CODE] IN { "A" }
)
RETURN
IF (
COUNTROWS ( countriescondition ) >= 4,
MAXX ( newtable, Data[DATE] ),
BLANK ()
)

 

If you write calculated measure, the table visualization already has the filter for the item, so I did not mention the item column in the calculated measure.

However, as you can see in the calculated column, I had to mention the item column.

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thanks for your reply and help. Your solution working well. 

Thanks for your reply and help. I will check and come back to you.

I am looking for New calculate column option can you please advise How can I get that. 

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.