Forum Discussion
Need help with my measures
- 5 years ago
Hi, svinayagam1984
I get it but the calculation is more complicated, because your needs are not suitable for multiple selection. If you want to do it, you need to create several virtual tables as var in the measure to calculate the previous week corresponding to the current week.
Like this(example lost):
flaglost = VAR tab = ADDCOLUMNS ( DISTINCT ( 'Date'[Date] ), "flag", VAR lastd = CALCULATE ( MAX( Data[Date]), FILTER ( ALL ( Data ), [Date] <EARLIER ( 'Date'[Date] ) ) ) VAR last = CALCULATETABLE ( DISTINCT ( Data[Customer] ), FILTER ( ALL ( Data ), [Date] = lastd ) ) VAR cur = CALCULATETABLE ( DISTINCT ( Data[Customer] ), FILTER ( ALL ( Data ), [Date] = EARLIER ( 'Date'[Date] ) ) ) RETURN IF ( MAX ( Data[Customer] ) IN EXCEPT (last, cur ), 1, 0 ) ) RETURN IF ( SUMX ( tab, [flag] ) > 0, 1,0 )Measurelostamount = VAR d = MINX ( FILTER ( Data, [flaglost] = 1 ), [Date] ) RETURN SUMX ( FILTER ( Data, [flaglost] = 1 && [Date] = d ), [Amount] )Measurelost = VAR tab = ADDCOLUMNS ( DISTINCT ( 'Date'[Date] ), "flag", VAR lastd = CALCULATE ( MAX ( Data[Date] ), FILTER ( ALL ( Data ), [Date] < EARLIER ( 'Date'[Date] ) ) ) VAR cur = CALCULATETABLE ( DISTINCT ( Data[Customer] ), FILTER ( ALL ( Data ), [Date] = EARLIER ( 'Date'[Date] ) ) ) VAR last = CALCULATETABLE ( DISTINCT ( Data[Customer] ), FILTER ( ALL ( Data ), [Date] = lastd ) ) RETURN COUNTROWS ( EXCEPT ( last, cur ) ) ) RETURN SUMX ( tab, [flag] )Note: Don't create relationships in dates or you can create a single distinct table as slicer.
If you still need help, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
This isn't feasible without using a separate date table.
As it is, when you filter to particular dates with your slicer, auto-exists filters your table to only those rows that match those dates, so the visual cannot display lost customers (they've been filtered out) and MIN(Data[Date]) is dependent on which customer is in the filter context.
- svinayagam19845 years agoHelper I
Thanks, AlexisOlson
I am very new to this DAX language and I am not able to get the desired result in Lost customer measures even after I add a separate date table.
This is my updated Sample file - Sample File
Please help me to fix this.