Forum Discussion
Calculate last hour data
- Anonymous6 years ago
Hi all,
I found the solution and want to share with you.
Please following this link.:
https://exceleratorbi.com.au/solving-a-complex-time-problem-in-power-bi/
Hello Anonymous ,
I currently cannot get the desired result.
Let me clarify a little bit, It's similar like DATEADD but applied for HOUR.
I cannot use this function due to the Time field data has the duplicate date.
Hi, Anonymous
As is suggested by az38 , It will work when the Time field has duplicate dates. I created data to reproduce your scenario.
Here is the measure.
Count Last 2 hours =
CALCULATE(
SUM('Table'[Count]),
FILTER(
ALLSELECTED('Table'),
DATEDIFF(
'Table'[Time],
SELECTEDVALUE('Table'[Time]),
HOUR
)=2
)
)
Result:
Here is the document about Dateadd function.
DATEADD(<dates>,<number_of_intervals>,<interval>)
It returns a table that contains a column of dates, shifted either forward or backward in time by the specified number of intervals from the dates in the current context.
| Term | Definition |
| dates | A column that contains dates. |
| number_of_intervals | An integer that specifies the number of intervals to add to or subtract from the dates. |
| interval | The interval by which to shift the dates. The value for interval can be one of the following: year, quarter, month, day |
There is no hour interval for the function. I don't think it is able to use Dateadd function in this scenario.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.