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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
MEDSEN
Frequent Visitor

Calculate days by criteria with DAX

Hello everyone, 

I have been having strugling trying to calculate the period an Item takes from receiving to shipping. 

in this example below I want to match the item number in Culumn "Item"( there is not specific item number lookup, the system numerically generate four identical item numbers for each of the four criterias in the Activity Type column) and calculate the period from column "Activity Date" by criteria from column " Activity Type".

 

IemActivity TypeActivity Date
22Receive1/15/2024
22Adjust1/16/1900
22Adjust1/16/2024
22Ship1/28/2024

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MEDSEN ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

Days Between = 
var receive = CALCULATE(MIN('Table'[Activity Date]), FILTER(ALL('Table'),'Table'[Activity Type] = "Receive" && 'Table'[Iem]=MAX('Table'[Iem])))
var ship = CALCULATE(MIN('Table'[Activity Date]), FILTER(ALL('Table'),'Table'[Activity Type] = "Ship" && 'Table'[Iem]=MAX('Table'[Iem])))

RETURN IF(SELECTEDVALUE('Table'[Activity Type]) = "Ship", DATEDIFF(receive, ship, DAY))

(3) Then the result is as follows.

vtangjiemsft_0-1706251147679.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

4 REPLIES 4
Anonymous
Not applicable

Hi @MEDSEN ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a measure. 

Days Between = 
var receive = CALCULATE(MIN('Table'[Activity Date]), FILTER(ALL('Table'),'Table'[Activity Type] = "Receive" && 'Table'[Iem]=MAX('Table'[Iem])))
var ship = CALCULATE(MIN('Table'[Activity Date]), FILTER(ALL('Table'),'Table'[Activity Type] = "Ship" && 'Table'[Iem]=MAX('Table'[Iem])))

RETURN IF(SELECTEDVALUE('Table'[Activity Type]) = "Ship", DATEDIFF(receive, ship, DAY))

(3) Then the result is as follows.

vtangjiemsft_0-1706251147679.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Thank you, Neeko! This is great. I very much appraciate it! 

MEDSEN
Frequent Visitor

Hello, Vicky.

Thank you so much for this measure. It opens the way to solve big part of the problem.

I was wondering i this measure would work when we have multiple "four identical numbers" in the smame column. 

What would be the best approach to this based on this scenario below:

 

IemActivity TypeActivity Date
22Receive1/15/2024
22Adjust1/16/1900
22Adjust1/16/2024
22Ship1/28/2024
58Receive2/1/2024
58Adjust2/4/2024
58Adjust2/5/2024
58Ship2/13/2024
102Receive3/5/2024
102Adjust3/10/2024
102Adjust3/12/2024
102Ship3/25/2024

 

vicky_
Super User
Super User

Days Between = 
var receive = CALCULATE(MIN('Table'[Activity Date]), 'Table'[Activity Type] = "Receive", ALLEXCEPT('Table', 'Table'[Iem]))
var ship = CALCULATE(MIN('Table'[Activity Date]), 'Table'[Activity Type] = "Ship", ALLEXCEPT('Table', 'Table'[Iem]))

RETURN IF(SELECTEDVALUE('Table'[Activity Type]) = "Ship", DATEDIFF(receive, ship, DAY))

Above is the formula for a DAX measure that i've come up with - basically, store the received and shipped dates as variables, and then return the days between if the type is ship. 

vicky__0-1705960304038.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors