Forum Discussion
Need help dax
Hello,
I need your help quickly please
I wanted to do the calculation of the next measurement and I did not find the right formula dax 😕
The formula and the following :
Open Missions Calculation:
Count nr of trips where end date is before ( end of current month – 42 days ) and approved / settled date is empty or after the end of current month
Current month: if selected quarter is in the past, end month of selected quarter, else if selected quarter is current quarter, then current calendar month.
I give you the exemple of the data I have in power BI in the following Excel file :
| Approved / Settled Date | End Date | Start Date | Number of Trips | Quarter (Approved/Settled) | Quarter (Start Date) | Quarter (End Date) | Year(Approved/Settled) | Year(Start Date) | Month( Start date) |
| 23-août-21 | 25-juil-21 | 14-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 24-août-21 | 02-août-21 | 26-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 25-août-21 | 12-juil-21 | 07-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 30-août-21 | 17-mai-21 | 12-mai-21 | 1 | Q3 2021 | Q2 2021 | Q2 2021 | 2021 | 2021 | May |
| 30-août-21 | 20-juin-21 | 17-juin-21 | 1 | Q3 2021 | Q2 2021 | Q2 2021 | 2021 | 2021 | June |
| 30-août-21 | 10-juil-21 | 07-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 30-août-21 | 25-juil-21 | 21-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 31-août-21 | 27-août-21 | 26-août-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | August |
| 03-sept-21 | 09-juil-21 | 07-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 06-sept-21 | 20-juin-21 | 17-juin-21 | 1 | Q3 2021 | Q2 2021 | Q2 2021 | 2021 | 2021 | June |
| 06-sept-21 | 11-juil-21 | 07-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 07-sept-21 | 30-juin-21 | 29-juin-21 | 1 | Q3 2021 | Q2 2021 | Q2 2021 | 2021 | 2021 | June |
| 07-sept-21 | 05-sept-21 | 01-sept-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | September |
| 08-sept-21 | 30-juil-21 | 28-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 09-sept-21 | 22-juil-21 | 17-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 10-sept-21 | 12-juil-21 | 06-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
| 14-sept-21 | 23-août-21 | 24-juil-21 | 1 | Q3 2021 | Q3 2021 | Q3 2021 | 2021 | 2021 | July |
Hi Nihed ,
Please try the following formula:
Measure = VAR NowQua = YEAR ( TODAY () ) & " Q" & QUARTER ( TODAY () ) VAR CurrentMonth = IF ( SELECTEDVALUE ( 'Calendar'[Quarter] ) = NowQua, FORMAT ( TODAY (), "yyyymm" ), MAX ( 'Calendar'[YearMonth] ) ) VAR EndDate = CALCULATE ( MAX ( 'Calendar'[Date] ), 'Calendar'[YearMonth] = CurrentMonth, ALL ( 'Calendar' ) ) VAR StartDate = EndDate - 42 RETURN CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( 'Table', 'Table'[End Date] <= StartDate && ( 'Table'[Approved / Settled Date] >= EndDate || 'Table'[Approved / Settled Date] = BLANK () ) ) )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- amitchandakSuper User
Nihed , refer if the current employee in this blog can help
- v-kkf-msftCommunity Support
Hi Nihed ,
Please try the following formula:
Measure = VAR NowQua = YEAR ( TODAY () ) & " Q" & QUARTER ( TODAY () ) VAR CurrentMonth = IF ( SELECTEDVALUE ( 'Calendar'[Quarter] ) = NowQua, FORMAT ( TODAY (), "yyyymm" ), MAX ( 'Calendar'[YearMonth] ) ) VAR EndDate = CALCULATE ( MAX ( 'Calendar'[Date] ), 'Calendar'[YearMonth] = CurrentMonth, ALL ( 'Calendar' ) ) VAR StartDate = EndDate - 42 RETURN CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( 'Table', 'Table'[End Date] <= StartDate && ( 'Table'[Approved / Settled Date] >= EndDate || 'Table'[Approved / Settled Date] = BLANK () ) ) )If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.