Forum Discussion
rainynights
Helper II
6 years agoUsing DAX to selectively pick 1 Day value from a list of possible matching days.
Let's say I'm a manager at a shipping company, and each time we get a category of an item, we need to know in a table when the next shipping date is. The table below illustrates an example of sh...
- 6 years ago
Create a calculate column using dax below:
Nearest Day = VAR Product_Type = 'Product Received Day'[Product Type] VAR Received_Day_Number = 'Product Received Day'[Received Day number] VAR Nearest_Day_Number_Later = CALCULATE ( MIN ( 'Shipment Days'[Shipment Day Number] ), FILTER ( 'Shipment Days', 'Shipment Days'[Shipment Day Number] >= Received_Day_Number && 'Shipment Days'[Product Category] = Product_Type ) ) VAR Nearest_Day_Number = IF ( Nearest_Day_Number_Later <> BLANK (), Nearest_Day_Number_Later, CALCULATE ( MIN ( 'Shipment Days'[Shipment Day Number] ), FILTER ( 'Shipment Days', 'Shipment Days'[Product Category] = Product_Type ) ) ) RETURN SWITCH ( Nearest_Day_Number, 1, "Monday", 2, "Tuesday", 3, "Wednesday", 4, "Thursday", 5, "Friday", 6, "Saturday", 7, "Sunday" )You can also refer to the pbix file attached.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yuta-msft
Community Support
6 years ago
Create a calculate column using dax below:
Nearest Day =
VAR Product_Type = 'Product Received Day'[Product Type]
VAR Received_Day_Number = 'Product Received Day'[Received Day number]
VAR Nearest_Day_Number_Later =
CALCULATE (
MIN ( 'Shipment Days'[Shipment Day Number] ),
FILTER (
'Shipment Days',
'Shipment Days'[Shipment Day Number] >= Received_Day_Number
&& 'Shipment Days'[Product Category] = Product_Type
)
)
VAR Nearest_Day_Number =
IF (
Nearest_Day_Number_Later <> BLANK (),
Nearest_Day_Number_Later,
CALCULATE (
MIN ( 'Shipment Days'[Shipment Day Number] ),
FILTER ( 'Shipment Days', 'Shipment Days'[Product Category] = Product_Type )
)
)
RETURN
SWITCH (
Nearest_Day_Number,
1, "Monday",
2, "Tuesday",
3, "Wednesday",
4, "Thursday",
5, "Friday",
6, "Saturday",
7, "Sunday"
)
You can also refer to the pbix file attached.
Community Support Team _ Jimmy Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.