ProtectorOfUbi
ProtectorOfUbi

Reputation: 327

I am calculating the difference between 2 variables in powerBI DAX when i visualise the measure i get "Error fetching data for this visual"

I am calculating the difference between 2 variables in powerBI DAX when i visualise the measure i get "Error fetching data for this visual" - I'm using a card to visualise the results.

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

enter image description here

I have tried the variables individually and displaying them with a card which works fine without issue.

its when i add the return line and attempt to calculate the difference an error appears.

so for example,

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

works just fine and so does the other function when used alone.

enter image description here

the answer i'm expecting is SouthvilleSales = £3.43m and CliftonEastSales = £3.2m = £230k

Upvotes: 1

Views: 243

Answers (1)

Amira Bedhiafi
Amira Bedhiafi

Reputation: 1

I checked and I can say it may be a bug as it is mentioned here : https://community.fabric.microsoft.com/t5/Service/Error-fetching-data-for-this-visual/m-p/4152009

You can try wrapping the measure in error-handling functions to help you in detecting issues with undefined results :

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
    )

enter image description here

Upvotes: 1

Related Questions