Forum Discussion
Help me Compare measures
Hi team,
I have a requirement in DAX.
I have two tables like below-
Table 1
| Date | D1 | D2 | D3 | D4 | M1 |
| June 1,2020 | 1 | 101 | 1101 | 11101 | 50 |
| June 1,2020 | 2 | 102 | 1102 | 11102 | 51 |
| June 1,2020 | 3 | 103 | 1103 | 11103 | 102 |
| June 2,2020 | 1 | 101 | 1101 | 11101 | 51 |
| June 2,2020 | 2 | 102 | 1102 | 11102 | 50 |
Table 2
| Date | D1 | D2 | D3 | M2 |
| June, 2020 | 1 | 101 | 1101 | 100 |
| June, 2020 | 2 | 102 | 1102 | 150 |
| June, 2020 | 3 | 103 | 1103 | 90 |
I need to create a measure like below-
Count(D4) whose sum(M1) by MTD from Table1>=M2 from Table2 ,for same values of D1,D2,D3,D4 combination in both tables.
For example,
When I select June 1st, for D1 = 1, D2 = 101 and D3 = 1101 combination, M1 = 50 from Table 1 which is less than M2 for the same combination of D1, D2, D3 from Table 2.So D4 in this case is not considered in count.
When I select June 2nd,
for D1 = 1, D2 = 101 and D3 = 1101 combination, M1 = 50 on June 1st and M1 = 51 on June 2nd.So MTD sum of M1 is 101 from Table 1 which is greater than M2 for the same combination of D1, D2, D3 from Table 2.So D4 in this case is considered in count.
Any pointers how this can be achieved.Please suggest.
Thanks,
Sam
- Anonymous6 years ago
Anonymous
Try the following:
1. Create a Running total Column :running total = CALCULATE(SUM('Table'[M1]),FILTER(ALLEXCEPT('Table','Table'[D1]),[Date]<=EARLIER('Table'[Date])))2. Then create the count measure:
Measure = CALCULATE(COUNT('Table'[D4]),FILTER('Table',[running total]>=RELATED('Table (2)'[M2])))Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- AnonymousNot applicable
Anonymous
Try the following:
1. Create a Running total Column :running total = CALCULATE(SUM('Table'[M1]),FILTER(ALLEXCEPT('Table','Table'[D1]),[Date]<=EARLIER('Table'[Date])))2. Then create the count measure:
Measure = CALCULATE(COUNT('Table'[D4]),FILTER('Table',[running total]>=RELATED('Table (2)'[M2])))Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - amitchandak
Super User
Anonymous , create a common dimension or create a combined key or both
Key = [D1] & "-" [D2]& "-" [D3]& "-" [D4]
Create a common dimension and display value against it
- AnonymousNot applicable
amitchandak .. I have edited the requirement, please check.I need to implement it in measure since sum(M1) is dynamic depending on selected date.Kindly suggest if there is a way to implement it in measure.