Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hi,
I've got recurring monthly sales data:
Customer a, 2024-01,500
Customer a, 2024-02,500
Customer b, 2024-01,300
Customer b, 2024-02,300
Customer b, 2024-02,300
Customer b, 2024-04,300
Customer c, 2024-04,200
So we "lost" customer a after 2024-02. I'm looking for a way to add this "lost" flag into the table.
Any ideas or suggestions?
Aim is to have table of:
Customer a, Lost (billed at some point in period)
Customer b, Active (continuous billing)
Customer c, Won (billing currently but not for whole period)
Solved! Go to Solution.
You can use below code as well for creating the calculated column
Flag =
VAR _MaxDate = MAX( 'Table'[Date] )
VAR _MaxDatebyCustomer =
CALCULATE(
MAX( 'Table'[Date] ), ALLEXCEPT( 'Table','Table'[Customer] )
)
VAR _NoOfSales =
CALCULATE(
COUNTROWS( 'Table'),
ALLEXCEPT( 'Table','Table'[Customer] )
)
VAR _Result =
IF(
_NoOfSales = 1,"Won",
IF(
_MaxDate = _MaxDatebyCustomer,
"Active",
"Lost"
) )
RETURN
Below screenshot
Regards
sanalytics
create two columns.
1、next_month
we can use the RANKX function to get the next month.
You can use below code as well for creating the calculated column
Flag =
VAR _MaxDate = MAX( 'Table'[Date] )
VAR _MaxDatebyCustomer =
CALCULATE(
MAX( 'Table'[Date] ), ALLEXCEPT( 'Table','Table'[Customer] )
)
VAR _NoOfSales =
CALCULATE(
COUNTROWS( 'Table'),
ALLEXCEPT( 'Table','Table'[Customer] )
)
VAR _Result =
IF(
_NoOfSales = 1,"Won",
IF(
_MaxDate = _MaxDatebyCustomer,
"Active",
"Lost"
) )
RETURN
Below screenshot
Regards
sanalytics
create a new column to determine the status of each customer. You can use the following DAX formula to create this column:
DAX
CustomerStatus =
VAR LastMonth = CALCULATE(MAX(Sales[Month]), ALLEXCEPT(Sales, Sales[Customer]))
VAR FirstMonth = CALCULATE(MIN(Sales[Month]), ALLEXCEPT(Sales, Sales[Customer]))
VAR CurrentMonth = MAX(Sales[Month])
RETURN
IF(
LastMonth = CurrentMonth,
IF(
FirstMonth = CurrentMonth,
"Won",
"Active"
),
"Lost"
)
Proud to be a Super User! |
|
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 5 | |
| 5 | |
| 4 | |
| 4 | |
| 3 |
| User | Count |
|---|---|
| 24 | |
| 21 | |
| 13 | |
| 10 | |
| 8 |