Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi everyone,
I wrote a DAX measure to try and get the days between orders for a particular customer - in the sample the name is Angela Mcintosh.
When I input the measure it's still showing all the customers when I just want it to show Angela Mcintosh.
Is there something that I could add or remove to fix this?
The code and screenshot is below thanks!
Also I got this error -
Hi @gbarr12345 ,
You need to filter out the values for that specific customer something similar to this should work:
DaysBetweenOrders =
VAR OrderNum =
MAX ( Orders[Order ID] )
VAR PreviousOrderID =
CALCULATE (
MAX ( Orders[Order ID] ),
FILTER (
ALLSELECTED ( Orders ),
Orders[Order ID] < OrderNum
&& Orders[Customer Name] = "Carrie Mcintosh"
)
)
VAR CurrentDate =
VALUE ( SELECTEDVALUE ( Orders[Order Date] ) )
VAR PriorDate =
VALUE (
CALCULATE (
SELECTEDVALUE ( Orders[Order Date] ),
FILTER ( ALL ( Orders ), Orders[Order ID] = PreviousOrderID )
)
)
RETURN
IF (
Orders[Customer Name] = "Angela Mcintosh"
&& OrderNum = CALCULATE ( MIN ( Orders[Order ID] ), ALLSELECTED ( Orders ) ),
0,
CurrentDate - PriorDate
)
Be aware that you refer Angela but on the first part of your calculation you refer Carrie
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsThanks for the response.
The IF statement part doesn't recognise Orders[Customer Name] = "Angela Mcintosh" part. It's not bringing up Orders[Customer Name] for me. Is there something I'm missing?
Hi @gbarr12345 ,
You are correct we need to specify the value of the customer try with this measure:
DaysBetweenOrders =
VAR OrderNum =
MAX ( Orders[Order ID] )
VAR PreviousOrderID =
CALCULATE (
MAX ( Orders[Order ID] ),
FILTER (
ALLSELECTED ( Orders ),
Orders[Order ID] < OrderNum
&& Orders[Customer Name] = "Carrie Mcintosh"
)
)
VAR CurrentDate =
VALUE ( SELECTEDVALUE ( Orders[Order Date] ) )
VAR PriorDate =
VALUE (
CALCULATE (
SELECTEDVALUE ( Orders[Order Date] ),
FILTER ( ALL ( Orders ), Orders[Order ID] = PreviousOrderID )
)
)
RETURN
IF (
SELECTEDVALUE(Orders[Customer Name]) = "Angela Mcintosh"
&& OrderNum = CALCULATE ( MIN ( Orders[Order ID] ), ALLSELECTED ( Orders ) ),
0,
CurrentDate - PriorDate
)
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsUser | Count |
---|---|
106 | |
88 | |
82 | |
76 | |
73 |
User | Count |
---|---|
112 | |
103 | |
96 | |
74 | |
67 |