Forum Discussion
Segmentation
- Anonymous8 years ago
I think I finally found the solution by Adjusting Dynamic Segmentation pattern to my case:
Cat = CALCULATE ( DISTINCTCOUNT(Customer[Id]), FILTER ( ADDCOLUMNS ( Customer,"CustomerDiff", CALCULATE ( FIRSTNONBLANK(TOPN ( 1, VALUES (FactTable[DiffInDays] ), FactTable[DiffInDays] ),1), CALCULATETABLE ( Customer ) ,ALLSELECTED () ) ), COUNTROWS ( FILTER ( 'Cat', NOT(ISBLANK([CustomerDiff])) && [CustomerDiff] >= Cat[MinDiff] && [CustomerDiff] <= Cat[MaxDiff] ) ) > 0 )
As I am not able to work with the earlier function I adjusted the formula:
Previous Date = var currentDate = FactTable[Date] var currentCustomer = FactTable[Id] VAR val = CALCULATE(MAX('FactTable'[Date]), FILTER(ALL('FactTable'), 'FactTable'[Date] < currentDate && 'FactTable'[Id] = currentCustomer ) ) return IF(ISBLANK(val),DATEVALUE("2017/01/01"),val)Is Earlier function better ?
Thank you Anonymous
You should be able to download the file. I have it tested by someone and he was able to dl it and open it.
Else try: https://www.justbeamit.com/aipfv
Even if I add the index, I still have the problem with the earlier in the previous year formula "EARLIER/EARLIEST refers to an earlier row context which doesn't exist. " for both Cutomer Id and Index
Regarding the KPI, imagine 3 cards visulization in power BI, each one for a category
10 20 15
Cat1 Cat2 Cat3
Thanks
I think I finally found the solution by Adjusting Dynamic Segmentation pattern to my case:
Cat = CALCULATE ( DISTINCTCOUNT(Customer[Id]), FILTER ( ADDCOLUMNS ( Customer,"CustomerDiff", CALCULATE ( FIRSTNONBLANK(TOPN ( 1, VALUES (FactTable[DiffInDays] ), FactTable[DiffInDays] ),1), CALCULATETABLE ( Customer ) ,ALLSELECTED () ) ), COUNTROWS ( FILTER ( 'Cat', NOT(ISBLANK([CustomerDiff])) && [CustomerDiff] >= Cat[MinDiff] && [CustomerDiff] <= Cat[MaxDiff] ) ) > 0 )
As I am not able to work with the earlier function I adjusted the formula:
Previous Date =
var currentDate = FactTable[Date]
var currentCustomer = FactTable[Id]
VAR val = CALCULATE(MAX('FactTable'[Date]),
FILTER(ALL('FactTable'),
'FactTable'[Date] < currentDate
&& 'FactTable'[Id] = currentCustomer
)
)
return IF(ISBLANK(val),DATEVALUE("2017/01/01"),val)Is Earlier function better ?
- Anonymous8 years agoNot applicable
Anonymous,
I can only reproduce your error when I create a measure using Earlier function. As my post, please create a calculate column, then apply the Earlier formula.
In your scenario, as long as you get expected previous date value using new DAX formula, it is OK.
Regards,Lydia