我正在计算 powerBI DAX 中两个变量之间的差异,当我可视化度量时,我得到“为该视觉对象获取数据时出错” - 我正在使用卡片来可视化结果。
SalesChange =
VAR SouthvilleSales =
CALCULATE(
SUM(Sales[Sales]),
Sales[StoreID] = 1, -- Assuming StoreID 1 represents Southville
Sales[CatID] = 2 -- Assuming CatID 2 represents 'Bracelets'
)
VAR CliftonEastSales =
CALCULATE(
SUM(Sales[Sales]),
Sales[StoreID] = 2, -- Assuming StoreID 2 represents Clifton East
Sales[CatID] = 2 -- Assuming CatID 2 represents 'Bracelets'
)
RETURN
SouthvilleSales - CliftonEastSales
我已经单独尝试了这些变量,并用卡片显示它们,效果很好,没有问题。
当我添加返回行并尝试计算差异时,会出现错误。
例如,
SalesChange =
VAR CliftonEastSales =
CALCULATE(
SUM(Sales[Sales]),
Sales[StoreID] = 2, -- Assuming StoreID 2 represents Clifton East
Sales[CatID] = 2 -- Assuming CatID 2 represents 'Bracelets'
)
RETURN
CliftonEastSales
单独使用时效果很好,其他功能也很好。
我期待的答案是 SouthvilleSales = 343 万英镑,CliftonEastSales = 320 万英镑 = 23 万英镑
我检查过,我可以说这可能是一个错误,因为这里提到:https://community.fabric.microsoft.com/t5/Service/Error-fetching-data-for-this-visual/m-p/4152009
您可以尝试将度量包装在错误处理函数中,以帮助您检测结果未定义的问题:
SalesChange v2 =
VAR SouthvilleSales =
CALCULATE(
SUM(Sales[Sales]),
Sales[StoreID] = 1,
Sales[CatID] = 2
)
VAR CliftonEastSales =
CALCULATE(
SUM(Sales[Sales]),
Sales[StoreID] = 2,
Sales[CatID] = 2
)
RETURN
IF(
ISBLANK(SouthvilleSales) || ISBLANK(CliftonEastSales),
BLANK(),
SouthvilleSales - CliftonEastSales
)