How to set time granularity of charts in workbooks ?

Baptiste GREAUD 21 Reputation points
2021-12-16T15:36:36.073+00:00

I'm implementing some queries in a workbook and I'm trying to visualize some of them as bar charts. The tables rendered are most of the time : timestamp(1d) - value. However, even though I have a value for each day, the time granularity of the chart displayed is 1h.
Is there a way to force the time granularity in a workbook or am I doing something wrong in my queries ?

Example of one of my query :

let timegrain = (seconds:long) {
    case(seconds < 3600, 1m, 
        seconds < 86400, 1h, 
        1d)
};

customEvents
| where timestamp {TimeRange}
| extend timestamp_adjusted = bin(timestamp, timegrain({TimeRange:seconds}))
| order by timestamp_adjusted asc, session_Id
| extend click = 1
| extend total=row_cumsum(click, session_Id != prev(session_Id))
| where name contains "go to"
| where operation_Id != prev(session_Id)
| project timestamp_adjusted, tot=total-1;
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,662 questions
0 comments No comments
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 21,551 Reputation points Moderator
    2021-12-20T11:05:19.153+00:00

    Hi @Baptiste GREAUD

    Welcome to Microsoft Q&A! Thanks for posting the question.

    Since you are using the where timestamp {TimeRange} clause, it would bind to the parameter as defined in your workbook. Based on the sample query, this parameter is named "TimeRange". Here is a sample of how it would look like in the workbook.

    158920-image.png

    Based on the user-defined function timegrain and its usage in the query above, the timegrain of the chart/output will depend on the value selected for TimeRange parameter. Can you please ensure that you are selecting the appropriate time range to get the desired result? For example,

    1. For granularity of 1 hour, please select a time range < 1 day (4 hours, 12 hours etc.).

    2. For granularity of 1 day, please select a range > 1 day (3 days, 7 days etc.).

    The below screenshot contains a sample query (somewhat similar to one provided in the question) and shows the impact of different TimeRange value.

    158994-image.png


    Time Range > 1 day

    158929-image.png


    Quick tip: * * For the chart's x-axis legend to show date, please select the **"Chart Setting"* and select "Custom formatting" check box (without making any other changes). Otherwise, the time offset from UTC gets shown as default.

    Please let me know if you have any questions.


    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.