Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Good afternoon Team,
I am looking for assistance in writing the DAX necessary to create a calculated column to help determine if a customer is lost or active and when. Here is the context of my data:
My table is of each contract in our database. The table contains columns for Corp-Name, Site-name, Site-ID, Contract-Date, Contract-Value, Contract-Expiration value. It's important to understand that a Site can have multiple contracts, and a customer can have multiple sites.
My goal for the new columns is if a customer has at least one active contract, at any site, then all rows for that customer must equal ACTIVE. Only once all contracts for all sites have expired are they to be calculated as LOST. Once a customer is LOST, I want a second column to be stripped with the MAX Expiration date of all the contracts for the sites of that customer. If active, then remain blank. Below is a visual of what I would expect the table to look like with the two new columns.
With these two new columns, I intend to count them and graph them based on lost date and show the sum of their lost contract values. I need them in column form for page filtering.
Here is how I attempted to calculate the CUSTOMER STATE, however, it is keeping context to the individual rows, and splitting the output for customers who are not truly lost but creating a row for the lost contracts and the active contracts.
Instead of below, this example should be "NOT LOST" instead of both.
Thank you in advance for your support in helping me get this customer status and lost date resolved!
Solved! Go to Solution.
H Smoody
Pleaase consider ths solution and leave kudos
Here are some DAX measure you can tweak ....
AllContractsForCustomer =
/*
This measure counts all contracts for a customer.
The ALL removes all the filters including the row context filter, then VALUES reapplies the customer context
*/
CALCULATE (
COUNTROWS(Contracts),
All (Contracts),
VALUES(Contracts[Customer])
)
ActiveContractsForCustomer =
/*
This measure counts all active contracts for the customer.
The ALL removes all the filters including the row context filter, then VALUES reapplies the customer context.
Then is just filters ACTIVE
*/
CALCULATE (
COUNTROWS(Contracts),
All (Contracts),
VALUES(Contracts[Customer]),
Contracts[Contract status]="ACTIVE"
)
InactiveContractsForCustomer =
/*
This measure counts all inactive contracts for the customer.
The ALL removes all the filters including the row context filter, then VALUES reapplies the customer context.
Then is just filters INACTIVE
*/
CALCULATE (
COUNTROWS(Contracts),
All (Contracts),
VALUES(Contracts[Customer]),
Contracts[Contract status]="INACTIVE"
)
I assume you just needed help overriding the row context. and you can do the rest from now on, because you seem to have a good grasp of IF logic.
@Anonymous add two calculated columns
Lost Y-N =
VAR __countActive =
CALCULATE (
COUNTROWS ( Table ),
ALLEXCEPT ( Table, Table[Customer] ),
Table[Contract State] = "Active"
)
RETURN
IF ( __countActive >= 1, "Active", "Inactive" )
Most Recent Expiration Date =
IF ( Table[Lost Y-N] = "Inactive",
CALCULATE (
MAX ( Table[Expiration Date]),
ALLEXCEPT ( Table, Table[Customer] )
)
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!
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@Anonymous add two calculated columns
Lost Y-N =
VAR __countActive =
CALCULATE (
COUNTROWS ( Table ),
ALLEXCEPT ( Table, Table[Customer] ),
Table[Contract State] = "Active"
)
RETURN
IF ( __countActive >= 1, "Active", "Inactive" )
Most Recent Expiration Date =
IF ( Table[Lost Y-N] = "Inactive",
CALCULATE (
MAX ( Table[Expiration Date]),
ALLEXCEPT ( Table, Table[Customer] )
)
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!
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Yes Parry, ALLEXCEPT is better than my suggestion
H Smoody
Pleaase consider ths solution and leave kudos
Here are some DAX measure you can tweak ....
AllContractsForCustomer =
/*
This measure counts all contracts for a customer.
The ALL removes all the filters including the row context filter, then VALUES reapplies the customer context
*/
CALCULATE (
COUNTROWS(Contracts),
All (Contracts),
VALUES(Contracts[Customer])
)
ActiveContractsForCustomer =
/*
This measure counts all active contracts for the customer.
The ALL removes all the filters including the row context filter, then VALUES reapplies the customer context.
Then is just filters ACTIVE
*/
CALCULATE (
COUNTROWS(Contracts),
All (Contracts),
VALUES(Contracts[Customer]),
Contracts[Contract status]="ACTIVE"
)
InactiveContractsForCustomer =
/*
This measure counts all inactive contracts for the customer.
The ALL removes all the filters including the row context filter, then VALUES reapplies the customer context.
Then is just filters INACTIVE
*/
CALCULATE (
COUNTROWS(Contracts),
All (Contracts),
VALUES(Contracts[Customer]),
Contracts[Contract status]="INACTIVE"
)
I assume you just needed help overriding the row context. and you can do the rest from now on, because you seem to have a good grasp of IF logic.
Thanks a ton! You hit the nail on the head for the issue. I completely forgot to get the except statement in there.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
90 | |
87 | |
84 | |
68 | |
49 |
User | Count |
---|---|
131 | |
111 | |
96 | |
71 | |
67 |