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.
v-janeyg-msft
Your solution is working like a charm.
I need more help from you!
How can we calculate the difference between the values?
Except New and lost, there are scenarios where a customer's value can be decreased or increased over time.
I want to show the difference between values in a different table.
Thanks in advance!
Hi, svinayagam1984
This is a new question. I think you can post a new post on the forum and describe the problem you want to solve completely, and then someone will answer it for you. 😊
Best Regards
Janey Guo