Forum Discussion
Calculate last day with condition
- 9 years ago
In this scenario, you apply the filter to limit the table context into "Answer = 0", the measure will not return result when the current context is "Answer =1". You may apply IF condition to combine the "last audit 0" and "last audit 1" into one measure.
To calculate the consecutive appearance, please refer to my expression in following thread:
http://community.powerbi.com/t5/Desktop/Count-last-actual-consecutive-sorted-rows/m-p/149683
Regards,
First of all, I would unpivot your date columns to end up with something like:
Item,Audit date,Value
Item A,07-03-2017,NA
Item A,08-03-2017,NA
Item A,09-03-2017,0
...
At that point, most of your calculations should be relatively trivial along the lines of wrapping a MAX function for Audit date in a CALCULATE with an appropriate FILTER clause.
thanks Greg_Deckler
Actually, my tables are normalized, I have two tables:
- VISITS to register visit dates
- AUDIT to register the answers of each visit
According to your suggestion, I created 3 new measures:
LAST AUDIT DATE = CALCULATE(MAX('TBL_VISITS'[AUDIT DATES]);
FILTER('TBL_AUDIT';'TBL_AUDIT'[ANSWER]>=0))
LAST 0 AUDIT = CALCULATE(MAX('TBL_VISITS'[AUDIT DATES]);
FILTER('TBL_AUDIT';'TBL_AUDIT'[ANSWER]=0))
LAST 1 AUDIT = CALCULATE(MAX('TBL_VISITS'[AUDIT DATES]);
FILTER('TBL_AUDIT';'TBL_AUDIT'[ANSWER]=1))
However I still have an issue, the results of "audit 0" and "audit 1" are reported ONLY when it was 0 or 1 respectively:
In the following sample, the column "Last 0 Audit" should report 13-12-2016 for the 2nd and 3rd row (03-01-2017 and 16-02-2017):
Any idea?
thank you!!!
- v-sihou-msft9 years ago
Microsoft Employee
In this scenario, you apply the filter to limit the table context into "Answer = 0", the measure will not return result when the current context is "Answer =1". You may apply IF condition to combine the "last audit 0" and "last audit 1" into one measure.
To calculate the consecutive appearance, please refer to my expression in following thread:
http://community.powerbi.com/t5/Desktop/Count-last-actual-consecutive-sorted-rows/m-p/149683
Regards,