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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
mina97
Helper III
Helper III

date difference with one simple condition

hey i have the following data 

 

ordersumitied datelast action datestatus
21612/10/202313/10/2023sumitied
21613/10/202313/10/2023returned to client
21620/10/202321/10/2023resubmited
21622/10/202330/10/2023Approved
21710/10/202310/10/2023sumitied
21710/10/202310/10/2023Approved

i want to calculate the date difference for the order from the day the order got retuned to client to the day the order got resubmitted only 
please help and thank you 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @mina97 

 

You can try the following methods. Create a new date table.

Date = CALENDAR(MIN('Table'[sumitied date]),MAX('Table'[last action date]))

vzhangti_0-1698662426985.png

Measure1 = 
Var _day1=CALCULATE(MAX('Table'[last action date]),FILTER(ALL('Table'),[status]="returned to client"))
Var _day2=CALCULATE(MAX('Table'[last action date]),FILTER(ALL('Table'),[status]="resubmited"))
Return
CALCULATE(COUNT('Date'[Date]),FILTER(ALL('Date'),[Date]>=_day1&&[Date]<=_day2&&[Weekday]<>5&&[Weekday]<>6))
Measure2 = 
Var _day1=CALCULATE(MAX('Table'[last action date]),FILTER(ALL('Table'),[status]="returned to client"))
Var _day2=CALCULATE(MAX('Table'[last action date]),FILTER(ALL('Table'),[status]="resubmited"))
Return
DATEDIFF(_day1,_day2,DAY)

vzhangti_1-1698662478362.png

Is this the result you expect? Please see the attached document.

 

Best Regards,

Community Support Team _Charlotte

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

3 REPLIES 3
v-zhangti
Community Support
Community Support

Hi, @mina97 

 

You can try the following methods. Create a new date table.

Date = CALENDAR(MIN('Table'[sumitied date]),MAX('Table'[last action date]))

vzhangti_0-1698662426985.png

Measure1 = 
Var _day1=CALCULATE(MAX('Table'[last action date]),FILTER(ALL('Table'),[status]="returned to client"))
Var _day2=CALCULATE(MAX('Table'[last action date]),FILTER(ALL('Table'),[status]="resubmited"))
Return
CALCULATE(COUNT('Date'[Date]),FILTER(ALL('Date'),[Date]>=_day1&&[Date]<=_day2&&[Weekday]<>5&&[Weekday]<>6))
Measure2 = 
Var _day1=CALCULATE(MAX('Table'[last action date]),FILTER(ALL('Table'),[status]="returned to client"))
Var _day2=CALCULATE(MAX('Table'[last action date]),FILTER(ALL('Table'),[status]="resubmited"))
Return
DATEDIFF(_day1,_day2,DAY)

vzhangti_1-1698662478362.png

Is this the result you expect? Please see the attached document.

 

Best Regards,

Community Support Team _Charlotte

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

mina97
Helper III
Helper III

1-exclude saturdays and fridays
2-including saturdays and fridays
🙂

hi @mina97 ,

not sure if i fully get you, you may try to plot a table visual with order column and two measures like:

WithoutFriSat = 
VAR _table = 
FILTER(
    data,
    data[order] = MAX(data[order])
)
VAR _day1 =
MAXX(
    FILTER(
        _table,
         data[status] = "returned to client"
    ),
    data[last action date]
)
VAR _day2 =
MAXX(
    FILTER(
        _table,
         data[status] = "resubmited"
    ),
    data[last action date]
)
VAR _days =
COUNTROWS(
    FILTER(
        CALENDAR(_day1, _day2),
        NOT WEEKDAY([date], 2) IN {5,6}
    )
)
RETURN 
IF( 
    ISBLANK(_day1)&&ISBLANK(_day2 ),
    BLANK(),
    _days
)
WithFriSat = 
VAR _table = 
FILTER(
    data,
    data[order] = MAX(data[order])
)
VAR _day1 =
MAXX(
    FILTER(
        _table,
         data[status] = "returned to client"
    ),
    data[last action date]
)
VAR _day2 =
MAXX(
    FILTER(
        _table,
         data[status] = "resubmited"
    ),
    data[last action date]
)
RETURN INT(_day2 - _day1) 

 

it worked like:

FreemanZ_0-1698309352595.png

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors