在绘制折线图时,常常引入目标值线(参考线),不同的年份,甚至不同的季度、年份目标值不同,如何实现呢?
通过我们通过增加目标值列来实现,以下是两种实现方法:
DAX写法:
目标值 =
SWITCH(
TRUE(),
'日期表'[年份] = 2024, 0.12,
'日期表'[年份] = 2025, 0.09,
'日期表'[年份] = 2026 && '日期表'[月份] = 1, 0.08, -- 注意:&& 代表“并且”
'日期表'[年份] = 2026 && '日期表'[月份] = 2, 0.10, -- 依次类推
'日期表'[年份] = 2026 && '日期表'[月份] = 3, 0.11,
0 -- 最后的 0 是默认值,防止前面的条件都不满足时返回空
)
M函数写法:
// 这是 M 语言的写法(仅供参考,不要混用)
Table.AddColumn(源, "目标值", each
if [年份] = 2024 then 0.12
else if [年份] = 2025 then 0.09
else if [年份] = 2026 and [月份] = 1 then 0.08
else 0
)
M函数实际公式:
= Table.AddColumn(更改的类型1, "目标", each if [年份] = 2024 then 0.82 else if [年份] = 2025 then 0.88
else if [年份] = 2026 and [月份]=1 then 0.90
else if [年份] = 2026 and [月份]=2 then 0.90
else if [年份] = 2026 and [月份]=3 then 0.90
else if [年份] = 2026 and [月份]=4 then 0.90
else if [年份] = 2026 and [月份]=5 then 0.91
else if [年份] = 2026 and [月份]=6 then 0.91
else if [年份] = 2026 and [月份]=7 then 0.91
else if [年份] = 2026 and [月份]=8 then 0.92
else if [年份] = 2026 and [月份]=9 then 0.92
else if [年份] = 2026 and [月份]=10 then 0.92
else if [年份] = 2026 and [月份]=10 then 0.92
else if [年份] = 2026 and [月份]=12 then 0.92
else 0)
本站部分内容搜集自公共网络,如侵犯了您的合法权利,请联系:info@daomen.net。
微信扫一扫