Greetings,
I have a requirement where i need to calculate the
sales order status from the point of a product was ordered.
the data which i have for one of the sales order id is as below for a customer.
Sample Data:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pdK9DkBAEATgV5GrXTJ36+doUahoVKJiC4kgV3h+p1aQ7GaameTrdhyVAUJ6PEe5ilXqXEKZboYqFOM0SFtYioASCFN38h51fmGvpvjTFzJvIfRG6O3L17ytF3te/nCS8UTGUxnPZDyX8ffntft1rPOjpxs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Sales Order ID (H)" = _t, #"Product ID (L)" = _t, SnapDate = _t, #"Sales Order Status Name (H)" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales Order ID (H)", type text}, {"Product ID (L)", type text}, {"SnapDate", type text}, {"Sales Order Status Name (H)", type text}})
in
#"Changed Type"
Here I am trying to calculate the initial sales order status and final sales order status in a measure based on the dates filters.
For this particular sales order id, the dates are from 18-03-2023 to 28-03-2023 and the initial status is Open Order so the measure should return Open Order and Invoiced as final status in all rows.
If the date range selected from 21-03-2023 to 24-03-2023 then the measures should return as below
Below is the dax which is working fine for me.
Sales order status Initial =
VAR _SalesOrderID = MAX('Sales Orders Snapshots'[Sales Order ID (H)])
VAR _ProductID = MAX('Sales Orders Snapshots'[Product ID (L)])
var _max = MINX(filter(ALLSELECTED('Sales Orders Snapshots'), 'Sales Orders Snapshots'[Sales Order ID (H)] = _SalesOrderID && 'Sales Orders Snapshots'[Product ID (L)] = _ProductID), 'Sales Orders Snapshots'[SnapDate])
return
CALCULATE(MAX('Sales Orders Snapshots'[Sales Order Status Name]), filter(ALLSELECTED('Sales Orders Snapshots') , 'Sales Orders Snapshots'[SnapDate] =_max && 'Sales Orders Snapshots'[Sales Order ID (H)] = _SalesOrderID && 'Sales Orders Snapshots'[Product ID (L)] = _ProductID))
But the issue with performance of this query.
When I do select individual sales order id or customer name from slicer, the query is running fine and showing the results.
But if I don't select anything from any of the slicer, it keeps spinning and after waiting for almost 15 to 20min it gives an error as Recourses exceeded try filtering to decrease the amount of data displayed.
The data size of this table is around 9,64,000 records.
Please help me to optimize the above dax.
Thanks in Advance. Mohan V.