Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi Masters,
Given is a table of status changes of customers (Old Status, New Status, Change Date, Previous Change Date) as described:
Also given is the column "First Purchase Date" which is constant for each Customer ID.
I wish to add a calculated column which will return the customer status of each customer while his first purchase.
in the example above, customer 123 first purchase date is 15/01/2022. therefore, according to his status changes dates his status while first purchase was "b" (15/1/2022 is between 01/01/2022 and 01/02/2022)
thanks for helping out.
Amit
Solved! Go to Solution.
hi @akfir
then try like:
StatusWhileFirstPurhcase2 =
VAR _customer = [CustomerID]
VAR _firstdate = [FirstPurchaseDate]
VAR _value1 =
MAXX(
FILTER(
TableName,
TableName[CustomerID]=_customer
&&TableName[StatusChangeDate]>=_firstdate
&&TableName[PreviousChangeDate]<=_firstdate
),
TableName[OldStatus]
)
VAR _value2 =
MAXX(
TOPN(
1,
FILTER(
TableName,
TableName[CustomerID]=_customer
),
TableName[StatusChangeDate]
),
TableName[NewStatus]
)
RETURN
IF( _value1<>BLANK(), _value1, _value2 )
hi @akfir
try to add a column like:
StatusWhileFirstPurhcase2 =
VAR _customer = [CustomerID]
VAR _firstdate = [FirstPurchaseDate]
RETURN
MAXX(
FILTER(
TableName,
TableName[CustomerID]=_customer
&&TableName[StatusChangeDate]>=_firstdate
&&TableName[PreviousChangeDate]<=_firstdate
),
TableName[OldStatus]
)
i worked like:
thanks for your quick reply!
it seems good but fail to show values in cases where FIRST PURCHASE DATE is larger than any status change date and then it returns BLANK instead of i guess NEW Status
yes please.
have a look in customer 456. First Purchase Date is later than latest Status change date. therefore value should be "d"
hi @akfir
then try like:
StatusWhileFirstPurhcase2 =
VAR _customer = [CustomerID]
VAR _firstdate = [FirstPurchaseDate]
VAR _value1 =
MAXX(
FILTER(
TableName,
TableName[CustomerID]=_customer
&&TableName[StatusChangeDate]>=_firstdate
&&TableName[PreviousChangeDate]<=_firstdate
),
TableName[OldStatus]
)
VAR _value2 =
MAXX(
TOPN(
1,
FILTER(
TableName,
TableName[CustomerID]=_customer
),
TableName[StatusChangeDate]
),
TableName[NewStatus]
)
RETURN
IF( _value1<>BLANK(), _value1, _value2 )
Perfect thanks!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
9 | |
8 | |
8 |
User | Count |
---|---|
14 | |
12 | |
11 | |
11 | |
8 |