Forum Discussion
need help formule in powerBI
Hello, hope someone kwow the right formula in DAX. I want to count the days in a contract is in a period. I use this formule:
_TotalDays of a contract in period =
For key1: i want see in 2022 count days between 1-8-2022 to 31-12-2022 and in 2023: 365 en in 2024: count days 1-1-2024 to 1-10-2024
I hope someone knows this, thanks a lot!!
Hi Margreet ,
Thanks for reaching out to the Microsoft fabric community forum.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
Best Regards,
Community Support Team
9 Replies
- lbendlin
Super User
The standard approach is to create two calendars (one for the contract duration and one for the filter context) and then use INTERSECT to see if they, well, intersect.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523- lbendlin
Super User
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523
- HarishKM
Super User
Margreet Hey,
Use below measure_TotalDays of a contract in period =
VAR StartPeriode = MIN(Datumtabel[Date]) VAR EindPeriode = MAX(Datumtabel[Date]) RETURN SUMX( FILTER( F_Contracten, RELATED(D_contracten[Ingangsdatum]) <= EindPeriode && RELATED(D_contracten[einddatum]) >= StartPeriode ), DATEDIFF( MAX(RELATED(D_contracten[Ingangsdatum]), StartPeriode), MIN(RELATED(D_contracten[einddatum]), EindPeriode), DAY ) + 1 )
Ensure that your date table (Datumtabel) covers all necessary dates and that your F_Contracten table includes the relevant contract information.
This formula should help you accurately count the days for each contract that overlaps with the given period.
Thanks
Harish M
Please accepts this as a solution if it is solve your problem and give kudos as well
- v-menakakota
Community Support
Hi Margreet ,
Thanks for reaching out to the Microsoft fabric community forum.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
Best Regards,
Community Support Team- v-menakakota
Community Support
Hi Margreet ,
We’re following up to check whether you were able to look into our earlier discussion. If you're still facing challenges, sharing a sample dataset will enable us to provide a focused and effective solution.
We’re here to help if you have any additional questions.
Thank you.- v-menakakota
Community Support
Hi Margreet ,
If you're still facing challenges, sharing a sample dataset will enable us to provide a focused and effective solution.We’re here to help if you have any additional questions.
Thank you.