Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tyan
Helper II
Helper II

How to calculate date

tyan_0-1648033351815.png

 

So I have such modeling. Four tables.

I need to create a measure/column : (Delivery Date - OC shipping date)= date to ship

My biggest question is if no show date in delivery date column then I will use actual delivery date, and do the same thing 

(actual Delivery Date- OC shipping date)

My priority is first use  DIMDELIVERY TABLE if empty then use DIMACTUALDELIVERY. 

How do i write this function ? 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @tyan ,

I created some data:

vyangliumsft_0-1648601685665.png

Here are the steps you can follow:

1. Create measure.

Actual Delivery date_measure =
CALCULATE(MAX('Dim Actual Delivery'[Actual Delivery date]),FILTER(ALL('Dim Actual Delivery'),'Dim Actual Delivery'[Group]=MAX('Fact Sales Table'[Group])))
Delivery date_measure =
CALCULATE(MAX('DimDelivery'[Delivery date]),FILTER(ALL('DimDelivery'),'DimDelivery'[Group]=MAX('Fact Sales Table'[Group])))
datediff =
IF(
   [Delivery date_measure]=BLANK(),
    DATEDIFF(
   MAX('Fact Sales Table'[OC Shipping date]),[Actual Delivery date_measure],DAY),
    DATEDIFF(
   MAX('Fact Sales Table'[OC Shipping date]),[Delivery date_measure],DAY))

2. Result:

vyangliumsft_1-1648601685666.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @tyan ,

I created some data:

vyangliumsft_0-1648601685665.png

Here are the steps you can follow:

1. Create measure.

Actual Delivery date_measure =
CALCULATE(MAX('Dim Actual Delivery'[Actual Delivery date]),FILTER(ALL('Dim Actual Delivery'),'Dim Actual Delivery'[Group]=MAX('Fact Sales Table'[Group])))
Delivery date_measure =
CALCULATE(MAX('DimDelivery'[Delivery date]),FILTER(ALL('DimDelivery'),'DimDelivery'[Group]=MAX('Fact Sales Table'[Group])))
datediff =
IF(
   [Delivery date_measure]=BLANK(),
    DATEDIFF(
   MAX('Fact Sales Table'[OC Shipping date]),[Actual Delivery date_measure],DAY),
    DATEDIFF(
   MAX('Fact Sales Table'[OC Shipping date]),[Delivery date_measure],DAY))

2. Result:

vyangliumsft_1-1648601685666.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

amitchandak
Super User
Super User

@tyan , if you have some common field like sales order id

 

then you try an approach like given in this blog

same in direct query

https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Differ...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.