Forum Discussion
Getting previous date by category, not min date
- 4 years ago
Thanks for clearer explanation, below you can try the new measure for the different of the days compare to previous ID.
Measure =var forid = SELECTEDVALUE('Table'[ID])var selectdate = SELECTEDVALUE('Table'[Date])var previousdate = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[ID]=forid-1))var result = DATEDIFF(previousdate,selectdate,DAY)returnIF(previousdate=BLANK(),BLANK(),result)
Another measure is the status:Status =var forid = SELECTEDVALUE('Table'[ID])var forcategory = SELECTEDVALUE('Table'[Category])var result = CALCULATE(MAX('Table'[Category]),FILTER(ALL('Table'),'Table'[ID]=forid-1))returnIF(result=BLANK(), BLANK(), IF(forcategory<>result, "Change", "No Change"))Hope this can help you.
- 4 years ago
Hi Anonymous
If the problem has been solved you can mark the reply for the standard answer to help the other members find it more quickly. If not, please point it out.
Looking forward to your feedback.
Best Regards,
Henry
Hi, you may try to use MAXX/MINX instead of MAX/MIN. and if you want to by category, you can add
var category1 = selectedvalue('category')
return
CALCULATE(IF(_previousBKT = _currentBKT && _MinDate = _Last,VALUE(UTCNOW()- _MinDate), DATEDIFF(_MinDate,_Last,DAY)), 'category' = 'category1')
Hope this can help you 😁
Hello, thanks for the reply. my goal is to return the date before max not min, but I can't use the earlier function in a measure (or can you?), below is my data simplified, in the table I need to compare ID 1 and 4 and get the datediff in days for aName
| 1 | aName | 7/30/22 |
| 2 | aName | 7/15/22 |
| 3 | aName | 7/1/22 |
| 4 | aName | 8/15/22 |
thanks for anu help on this
- Chew_WenJie4 years ago
Resolver III
Hello, earlier function are normally used in the calculated column instead of measure. You may refer to the power bi that i had attached below, the measure i done is datediff based on the ID of the name.
Dummy data:
Sample measure result:Measure:
Measure =var aname = SELECTEDVALUE('Table'[Name])var findminID = CALCULATE(MIN('Table'[ID]),'Table'[Name]=aname)var findmaxID = CALCULATE(MAX('Table'[ID]),'Table'[Name]=aname)var find1stdate = CALCULATE(MAX('Table'[Date]),'Table'[ID]=findminID)var findlastdate = CALCULATE(MAX('Table'[Date]),'Table'[ID]=findmaxID)var datedifferent = DATEDIFF(find1stdate,findlastdate,DAY)returndatedifferent.
Hope this can help you
- Anonymous4 years agoNot applicable
Hello, thanks for the response. in my data Min(ID) will return the first record in the group, this is not the record I want, I am looking for previous date, as I add new records I am checking for change from the most recent.
Thanks
- Chew_WenJie4 years ago
Resolver III
Maybe, you can show me what is the result you wanted from this table, i believe that i will have a better understanding on your requirement.