Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric 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êsJoin the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Ask questions in Eventhouse and KQL, Eventstream, and Reflex.
User | Count |
---|---|
85 | |
83 | |
66 | |
60 | |
57 |
User | Count |
---|---|
188 | |
111 | |
105 | |
78 | |
71 |