Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have several records with a StartDate and an EndDate of a period.
I need to calculate days between this dates.
The real problem is in filtering the data.
For example If i have a StartDate = DATE(2018,1,1) and an EndDate(2018,2,2) and I would like to filter the period in February, the formula have to return two days
Solved! Go to Solution.
Hi @lfrigione,
Just to clarify one thing, in the GIF beware that the dates are in US format (an error of PBI that is being solved), so the dates from 1/1/2017 - 3/1/2017 is January 1st to March 1st in this case is 10 days.
If you change the slicer to January 1st to January 3rd you get 3 days because in my formula I added +1 didn't know if you want the datediff result or the count of all days, just make the formula like this:
Counting_days = VAR START_DATE = MIN ( DimDate[Date] ) VAR END_DATE = MAX ( DimDate[Date] ) RETURN SUMX ( SUMMARIZE ( FactTable; FactTable[StartDate]; FactTable[EndDate]; "DAYS"; IF ( FactTable[StartDate] < START_DATE && FactTable[EndDate] < START_DATE || FactTable[StartDate] > END_DATE && FactTable[EndDate] > END_DATE; 0; DATEDIFF ( IF ( FactTable[StartDate] < START_DATE; START_DATE; FactTable[StartDate] ); IF ( FactTable[EndDate] > END_DATE; END_DATE; FactTable[EndDate] ); DAY ) ) ); [DAYS] )
But be aware that if you get the period from 1 January to 1 January de days difference is 0 and not 1.
See the PBIX sample with the formula above working and try to check if this is the resul you want.
Regards,
MFelix
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsI have an Idea,
Can I create a calculated colum in the calendar that represent the number of periods that contains the day?.
For every record it have to calcuate how many periods meet this condition: FactTable[StartDate] <= CurrentDay <= FactTable[EndDate]
and save this information or something like that.
Thanks again,
lfrigione.
Hi @lfrigione,
Due work schedulle, I was not abble to give you an answer yet.
Wil try to work on this ASAP and return back to you.
Sorry for the delay.
MFelix
Regards
Miguel Félix
Proud to be a Super User!
Check out my blog: Power BI em PortuguêsCovering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
100 | |
76 | |
74 | |
49 |
User | Count |
---|---|
146 | |
108 | |
106 | |
90 | |
62 |