基于用户参数的不同 X 轴刻度

Different X axis scale based on user parameter

我正在尝试制作一个仪表板,用户可以在其中使用参数 select X 轴刻度。

因此,如果他们选择“月份”,则 X 轴将按如下所示按月份细分

tilldevicedata
| where todatetime(TransactionTimeStampUtc) between (_startTime.._endTime)
| where Brand has_any (_brand)
| where Country == _country
| where Store has_any (_store)
| summarize TotalSales = sum(TransactionValueGross) by monthofyear(todatetime(TransactionTimeStampUtc))

如果他们选择周,那么我希望细分是按年而不是按年

如何根据 Data Explorer 仪表板中的用户参数使这部分查询成为条件?

-- 编辑--

我试图让它动态化,但我只有 monthofyear,它从来没有达到 dayofyear,我不明白为什么

let _timePeriodInHours = datetime_diff("Hour", _startTime, _endTime);

    tilldevicedata
    | where todatetime(TransactionTimeStampUtc) between (_startTime.._endTime)
    | where Brand has_any (_brand)
    | where Country == _country
    | where Store has_any (_store)
    | summarize TotalSales = sum(TransactionValueGross) by case(_timePeriodInHours < 1, monthofyear(todatetime(TransactionTimeStampUtc)), _timePeriodInHours > 1, dayofyear(todatetime(TransactionTimeStampUtc)), _timePeriodInHours)

示例查询
注意 summarize ... by case(...)

的使用
range i from 1 to 10000 step 1    
| extend dttm = ago(1000d * rand())
| summarize count() by case(_period == 'month', startofmonth(dttm), _period == 'week', startofweek(dttm), datetime(null))
| render timechart

_period参数定义