Skip to main content
Solved

trying to get ActivityEvents from PowerBI admin for more than one day using TimeXtender REST API

  • March 5, 2026
  • 10 replies
  • 68 views

Hi,

i want to retrieve ActivityEvents from PowerBI Admin using then TimeXtender REST API.

configure the base URL as: https://api.powerbi.com/v1.0/myorg/admin/
Endpoint configured as: activityevents?StartDateTime=%27{BDAT}%27&EndDateTime=%27{EDAT}%27&filter=Activity%20eq%20%27ViewReport%27

{BDAT} and {EDAT} are populated using a SQL Query:
 

DECLARE @i int = 0

WHILE @i > -5
BEGIN
    select CONCAT(FORMAT(dateadd(day,@i,GETDATE()), 'yyyy-MM-dd'),'T00%3A05%3A00.000') as [BDAT],
    CONCAT(FORMAT(dateadd(day,@i,GETDATE()), 'yyyy-MM-dd'),'T23%3A55%3A00.000') as [EDAT]
    SET @i = @i - 1
END

i hoped it will loop for the past 5 days but unfortunately this doesn't work.

Setting the BDAT 5 days in the past doesn't work either. 

Any ideas how to solve this?

by the way we are using TX Classic V 20.10.66.64 and TimeXtender REST API v16.4.23.0 (also tested with 16.4.21.0)

Kind regards,

Hans

 

Best answer by HansZZV

solved it using the below query instead of the original while loop 

with basis as (SELECT TOP 5 ROW_NUMBER() OVER (ORDER BY (SELECT NULL))*-1 AS Nummer
FROM sys.all_objects)
  select CONCAT(FORMAT(dateadd(day, b.nummer,GETDATE()), 'yyyy-MM-dd'),'T00%3A05%3A00.000') as [BDAT],
  CONCAT(FORMAT(dateadd(day,b.nummer,GETDATE()), 'yyyy-MM-dd'),'T23%3A55%3A00.000') as [EDAT]
  from (SELECT TOP 5 ROW_NUMBER() OVER (ORDER BY (SELECT NULL))*-1 AS Nummer
FROM sys.all_objects) b

10 replies

  • Problem Solver
  • March 9, 2026

“this doesn't work” OK, so what happens? Any error messages? No results? Wrong results? Too many results?

Are BDAT and EDAT in the exact format the endpoint is expecting?


rory.smith
TimeXtender Xpert
Forum|alt.badge.img+8
  • TimeXtender Xpert
  • March 9, 2026

Hi,

if you turn on debug logging you will be able to see what call URI gets generated which will help with tuning the query you are using. With respect to the query: I would rewrite that query to be a bit better - if you are on SQL 2022+ you can use generate series:

WITH d AS 
(
SELECT DATEADD(DAY, -s.value, CAST(SYSDATETIME() AS date)) AS d
FROM GENERATE_SERIES(0, 4) AS s
)
SELECT
CAST(d AS datetime2(0)) AS [startTime],
DATEADD(SECOND, -1, DATEADD(DAY, 1, CAST(d AS datetime2(0)))) AS [endTime]
FROM d
ORDER BY [startTime]

For SQL 2019 and older:


WITH n(i) AS
(
SELECT i FROM (VALUES (0),(1),(2),(3),(4)) AS v(i)
),
d AS
(
SELECT DATEADD(DAY, -i, CAST(SYSDATETIME() AS date)) AS d
FROM n
)
SELECT
CAST(d AS datetime2(0)) AS [startTime],
DATEADD(SECOND, -1, DATEADD(DAY, 1, CAST(d AS datetime2(0)))) AS [endTime]
FROM d
ORDER BY [startTime]

You can use a tally table if you need more than a handful of days and use the FORMAT() function to tune the output string representation of the timestamps.


  • Author
  • Starter
  • March 10, 2026

I get data in the ODX but just for one day, the current date. (@i = 0)


  • Problem Solver
  • March 10, 2026

Probably because your piece of SQL effectively generates five queries and only the first one is actually used. You should change that so your query returns five rows in one result set.

Something like this. There are better ways to do it ;)

with x as (select 0 as x union select 1 union select 2 union select 3 union select 4)
select CONCAT(FORMAT(dateadd(day,-x.x,GETDATE()), 'yyyy-MM-dd'),'T00%3A05%3A00.000') as [BDAT],
CONCAT(FORMAT(dateadd(day,-x.x,GETDATE()), 'yyyy-MM-dd'),'T23%3A55%3A00.000') as [EDAT]
from x

 


  • Author
  • Starter
  • Answer
  • March 10, 2026

solved it using the below query instead of the original while loop 

with basis as (SELECT TOP 5 ROW_NUMBER() OVER (ORDER BY (SELECT NULL))*-1 AS Nummer
FROM sys.all_objects)
  select CONCAT(FORMAT(dateadd(day, b.nummer,GETDATE()), 'yyyy-MM-dd'),'T00%3A05%3A00.000') as [BDAT],
  CONCAT(FORMAT(dateadd(day,b.nummer,GETDATE()), 'yyyy-MM-dd'),'T23%3A55%3A00.000') as [EDAT]
  from (SELECT TOP 5 ROW_NUMBER() OVER (ORDER BY (SELECT NULL))*-1 AS Nummer
FROM sys.all_objects) b


Forum|alt.badge.img+1
  • Contributor
  • March 10, 2026

Hi ​@HansZZV 

Have you tried to get the dates in a single query instead of loop, something like this?

 

WITH dates AS (
SELECT 0 AS i
UNION ALL
SELECT i - 1
FROM dates
WHERE i > -4
)
SELECT
CONCAT(FORMAT(DATEADD(DAY, i, GETDATE()), 'yyyy-MM-dd'), 'T00%3A05%3A00.000') AS BDAT,
CONCAT(FORMAT(DATEADD(DAY, i, GETDATE()), 'yyyy-MM-dd'), 'T23%3A55%3A00.000') AS EDAT
FROM dates
OPTION (MAXRECURSION 10);

 


rory.smith
TimeXtender Xpert
Forum|alt.badge.img+8
  • TimeXtender Xpert
  • March 10, 2026

Hi,

I posted a long reply but it is waiting for moderation (perhaps because I included code snippets). I would turn on debug logging so you can see what the output of your SQL query is and whether that call would actually work. I would also rewrite your SQL query to avoid a while loop and simply subtract a second or millisecond from the todate to avoid all the formatting stuff.


  • Problem Solver
  • March 10, 2026

My reply including a suggestion for a different query is being held for moderation too. 

Your SQL generates five different querys (and five result sets) instead of just one so only the first one is actually used.


  • Problem Solver
  • March 11, 2026

Holding replies for moderation is a good way to stop users from trying to come op with solutions.


Christian Hauggaard
Community Manager
Forum|alt.badge.img+5

Hi ​@RLB ​@rory.smith 

Sorry the automatic spam detection mistakenly removed the replies, I have marked them as not spam now, we sincerely apologize for this. Thank you very much for your input