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
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:
.
Hope this can help you
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.
- Anonymous4 years agoNot applicable
Thanks, I am testing your measure but not getting the right result. this is a better sample of the actual data. as I add new records I need to compare to the previous date, when I add ID 2, compare to ID 1, when I add ID 3, compare to ID 2. Below sample shows ID 5, I need to compare to ID 4. Using Min and Max return ID 1 and ID 5 which is not what I need to check for name change. Thank for your help
ID Category Date Status Days 1 aName 7/27/22 2 aName 8/10/22 No Change 14 days 3 aName 8/17/22 No Change 21 Days 4 bName 8/25/22 Change 1 Days 5 bName 9/1/22 No Change 6 Days - Chew_WenJie4 years ago
Resolver III
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.