Forum Discussion
Create a new column based on one value in a group
| Customer | Date | Order Amount | ||
| Customer A | Jan 20 | 10 | ||
| Customer A | Feb 20 | 5 | ||
| Customer A | Mar 20 | 10 | ||
| Customer B | Feb 20 | 20 | ||
| Customer B | Mar 20 | 5 | ||
| Customer B | May 20 | 20 | ||
| Customer C | May 20 | 10 |
Expected Result:
I want to add a column, that identifies all "Active Customers", based on whether they have made an order in the current month (May 2020) or not. The result I want to achieve looks like this:
| Customer | Date | Order Amount | Active Customer | |||
| Customer A | Jan 20 | 10 |
| No | ||
| Customer A | Feb 20 | 5 |
| No | ||
| Customer A | Mar 20 | 10 |
| No | ||
| Customer B | Feb 20 | 20 |
| Yes | ||
| Customer B | Mar 20 | 5 |
| Yes | ||
| Customer B | May 20 | 20 |
| Yes | ||
| Customer C | May 20 | 10 |
| Yes |
Any help getting closer to this result is highly appreciated!
try following
Flag = VAR __latestDate = CALCULATE ( MAX ( Table[Date] ), ALLEXCEPT ( Table, Table[Customer] ) ) VAR __latestEOM = EOMONTH ( __latestDate, 0 ) VAR __todayEOM = EOMONTH ( TODAY(), 0 ) RETURN IF ( __latestEOM = __todayEOM, "YeS", "No" )I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
3 Replies
- parry2k
Super User
try following
Flag = VAR __latestDate = CALCULATE ( MAX ( Table[Date] ), ALLEXCEPT ( Table, Table[Customer] ) ) VAR __latestEOM = EOMONTH ( __latestDate, 0 ) VAR __todayEOM = EOMONTH ( TODAY(), 0 ) RETURN IF ( __latestEOM = __todayEOM, "YeS", "No" )I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
- AnonymousNot applicable
I think its actually probably simpler to add a field to your customer table with the most recent order date, and then relate those two tables. That way you can cross filter all relevant customer facts and dims on the attribute.
By the way, parry2k's solution should work but I find the answer a bit too specific.
Feel free to reply here if you need more help with what i mean.
- v-gizhi-msft
Community Support
Hi,
Please try a simpler logic column as below:
Active Customer = IF ( CALCULATE ( COUNT ( 'Table'[Customer] ), FILTER ( 'Table', 'Table'[Customer] = EARLIER ( 'Table'[Customer] ) && MONTH ( 'Table'[Date] ) = MONTH ( TODAY () ) ) ) >= 1, "Yes", "No" )The result shows:
See my attached pbix file.
Best Regards,
Giotto