Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
Hi All,
I have a requirement to calculate the difference between two dates. Please find sample data below:
| Protocol | Start Date | Status | End Date |
| A | 9/26/2022 | In-Progress | 11/20/2022 |
| A | 9/26/2022 | Closed | 11/20/2022 |
| B | 3/3/2022 | In-Progress | 4/12/2022 |
| B | 3/3/2022 | Testing | 4/12/2022 |
| B | 3/3/2022 | Closed | 4/12/2022 |
Expected Output:
| Protocol | No.of days |
| A | 55 |
| B | 40 |
Wrong output that I am getting:
| Protocol | No.of days |
| A | 110 |
| B | 120 |
Issue is that, the no. of days are been aggregared.
Eg: No. of days between 9/26/2022 and 11/20/2022 for protocol A is 55. But since there are two satutses for a single protocol, the days are getting aggregated resulting in 110.
I have created a new column with below dax.
newcolumn=datediff([startdate],[enddate],day)
Removing the 'Don't Summarize' option did not work as I will be using this to calcualte the Average.
Expected Average is (55+40)/2=47.5 but I get (110+120)/2=115
Could someone please advise on how to achieve this using DAX.
Thank you.
Solved! Go to Solution.
Simplest dax can be as follows.
SUMX(SUMMARIZE('Table','Table'[protocol],'Table'[start],'Table'[end],"datediff",DATEDIFF('Table'[start],'Table'[end],DAY)),[datediff]).
This will give you was u required.
Summarize is good approach to avoid certain columns which creates aggregation or double dip on values
@POSPOS , then replace the closed status in the measure into open, thus you'll take one row.
If I answered your question, please mark my post as solution, Appreciate your Kudos 👍
Follow me on Linkedin
Vote for my Community Mobile App Idea 💡
Proud to be a Super User! | |
Simplest dax can be as follows.
SUMX(SUMMARIZE('Table','Table'[protocol],'Table'[start],'Table'[end],"datediff",DATEDIFF('Table'[start],'Table'[end],DAY)),[datediff]).
This will give you was u required.
Summarize is good approach to avoid certain columns which creates aggregation or double dip on values
@Anonymous - thank you for the response. This solution worked.
You are most welcome:-)
Hello @POSPOS ,
would this work for you
If I answered your question, please mark my post as solution, Appreciate your Kudos 👍
Follow me on Linkedin
Vote for my Community Mobile App Idea 💡
Proud to be a Super User! | |
@Idrissshatila - Not all are having the same list of statuses. Some of them may still be open.
@Idrissshatila : Restricting by one statuses may not work for the data that we have as we have some of the protocols which are directly approved and hence they just have one status called 'approved' without open/close/in-progress.
Each of them may have a different criteria of statuses/
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 48 | |
| 40 | |
| 38 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 68 | |
| 65 | |
| 30 | |
| 26 | |
| 25 |