Forum Discussion
DATEDIFF DAX measure
- Anonymous5 years ago
Hi ka047 ,
The SUMMARIZE function returns a summary table. If you want to calculate the difference between 2 date fields, try this:
Shipping Days = DATEDIFF ( Fact_SalesCogs[DeliveryDate], Fact_SalesCogs[ShippingDateConfirmed], DAY )If you want to create a calculated table which has Shipping Days column, try this:
New Table = SUMMARIZE ( Fact_SalesCogs, Fact_SalesCogs[SalesOrder], Fact_SalesCogs[DeliveryDate], Fact_SalesCogs[ShippingDateConfirmed], "Shipping Days", DATEDIFF ( 'Fact_SalesCogs'[DeliveryDate], Fact_SalesCogs[ShippingDateConfirmed], DAY ) )The pbix file I tested is here.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ka047 , Try like
Shipping Days =
Sumx(summarize (Fact_SalesCogs,
Fact_SalesCogs[SalesOrder],
Fact_SalesCogs[DeliveryDate],
Fact_SalesCogs[ShippingDateConfirmed],
"_1",
calculate(
datediff(min(Fact_SalesCogs[DeliveryDate]), max(Fact_SalesCogs[ShippingDateConfirmed]), day))), [_1])
or
Shipping Days =
Sumx(summarize (Fact_SalesCogs,
Fact_SalesCogs[SalesOrder],
Fact_SalesCogs[DeliveryDate],
Fact_SalesCogs[ShippingDateConfirmed],
Fact_SalesCogs[DeliveryDate],
Fact_SalesCogs[ShippingDateConfirmed])
,datediff(min(Fact_SalesCogs[DeliveryDate]), max(Fact_SalesCogs[ShippingDateConfirmed]), day))