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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
asanand
Regular Visitor

Finding the max date row between date range and date range is dynamic.

Hello 

I am new to PowerBI and looking for one solution. I tired to find the solution in this forum and do a lot of google but not able to find anything related to this. 

 

Problem: 

There is a transaction table with multiple values for a transaction happened on different dates. Now we want to pick the max row as per the date range selected from the slicer. 

 

For eg: if user selects Jan 1 2017 till Jan 15 2017 then all the records which lie between these dates should be considered but we will pick the record with the max date from those records with in the above selected date range. 

 

Like if one value having Jan 7th as the max date we will pick 7th record and if another record has the max date of 1 we will pick the 1st record. Similiarly if any record having 100 records but the max date is 7th we will pick record with the date 7th and even if the records having 100 records with the date range going beyond Jan 15 2017, we will only consider records between the date range selected by the user. 

 

I hope I am able to well explain this problem. Following a example I tried to create for better understanding. Looking for the help from the community, I am all set and excited about powerbi 🙂

  

We would like to do something like this

 

T11-Jan-17 
T12-Jan-17 
T13-Jan-17 
T14-Jan-17 
T15-Jan-17 
T16-Jan-17 
T17-Jan-17 
T21-Jan-17 
T23-Jan-17 
T24-Jan-17 
T28-Jan-17 
T215-Jan-17 
T34-Jan-17 
T36-Jan-17 
T37-Jan-17 
T326-Jan-17 
T35-Feb-17 
   
Selection: 11-Jan-177-Jan-17
T17-Jan-17 
T37-Jan-17 
   
   
   
Selection : 215-Jan-1730-Jan-17
T215-Jan-17 
T326-Jan-17 
   
1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @asanand,

 

You can use below formula to get the max date of each type based on slicer:

 

Measure:
Max Date = 
var curr=LASTNONBLANK(Sheet4[Column1],[Column1])
Return
MAXX(FILTER(ALLSELECTED(Sheet4),[Column1]=curr),[Column2]) 

 

Capture.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

6 REPLIES 6
v-shex-msft
Community Support
Community Support

Hi @asanand,

 

You can use below formula to get the max date of each type based on slicer:

 

Measure:
Max Date = 
var curr=LASTNONBLANK(Sheet4[Column1],[Column1])
Return
MAXX(FILTER(ALLSELECTED(Sheet4),[Column1]=curr),[Column2]) 

 

Capture.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft Hello, This is not working with Direct Query. Is there a way to rewrite this which will work with Direct Query? 

 

Thanks 

I am able to enable the functions via options and its working now. Thanks for your help on this. Appreciate it!!!

Thank you for your help and though it returning me the correct date but when I am trying to sum the flags its not counting it correct and counting the values multiple time. This is what I have done, can you please take a look and advise what's wrong with this. Thanks 

 

YieldPassCount = VAR curr =
LASTNONBLANK (
Dashboard_MCS_YieldReports[Stop_Time],
Dashboard_MCS_YieldReports[Stop_Time]
)
RETURN CALCULATE(SUM(Dashboard_MCS_YieldReports[PassFlag]),FILTER(Dashboard_MCS_YieldReports,(
MAXX (
FILTER (
ALLSELECTED ( Dashboard_MCS_YieldReports ),
( Dashboard_MCS_YieldReports[Stop_Time] = curr )
),
Dashboard_MCS_YieldReports[Stop_Time]
))),GROUPBY(Dashboard_MCS_YieldReports,Dashboard_MCS_YieldReports[SerialNumber],Dashboard_MCS_YieldReports[AssemblyName]))

Thanks for the reply, I will check this and will let you know. 

Habib
Responsive Resident
Responsive Resident

Please use DatesBetween filter inside a calculate functon.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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