Forum Discussion

asanand's avatar
asanand
Regular Visitor
9 years ago
Solved

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 
   
  • Anonymous's avatar
    Anonymous
    9 years ago

    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]) 

     

     

    Regards,

    Xiaoxin Sheng

6 Replies

  • Habib's avatar
    Habib
    Icon for Continued Contributor rankContinued Contributor

    Please use DatesBetween filter inside a calculate functon.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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]) 

     

     

    Regards,

    Xiaoxin Sheng

    • asanand's avatar
      asanand
      Regular Visitor

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

    • asanand's avatar
      asanand
      Regular Visitor

      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]))

    • asanand's avatar
      asanand
      Regular Visitor

      Anonymous Hello, This is not working with Direct Query. Is there a way to rewrite this which will work with Direct Query? 

       

      Thanks 

      • asanand's avatar
        asanand
        Regular Visitor

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