Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Power_steffi
Regular Visitor

Previous Year empty values

I'm trying to calculate the sales for the previous year in Power BI using DAX formulas, but all the formulas that I've tried are giving me blank values. I wanted to calculate the growth but I realized just the previous year, already give me empty values. 

 

Sales Previous Year = CALCULATE([Total Sales], SAMEPERIODLASTYEAR(raw[Inv. Date]))

Sales Previous Year = CALCULATE([Total Sales], FILTER(raw, raw[Year] = MAX(raw[Year])-1 && raw[Quarter] = MAX(raw[Quarter]) && raw[Month] = MAX(raw[Month])))

Sales Previous Year = CALCULATE([Total Sales], DATEADD(raw[Inv. Date], -1, YEAR))

Sales Previous Year = CALCULATE([Total Sales], PREVIOUSYEAR(raw[Inv. Date]))

% Change = 
VAR CurrentValue = raw[Total Sales]
VAR PREviousValue = 
    SWITCH(
        TRUE(),
        ISINSCOPE(raw[Inv. Date].[Date]), 
            CALCULATE([Total Sales], 
                DATEADD(raw[Inv. Date], -1, DAY)
            ),
        ISINSCOPE(raw[Inv. Date].[Monat]), 
            CALCULATE([Total Sales], 
                PARALLELPERIOD(raw[Inv. Date], -1, YEAR)
            ),
        ISINSCOPE(raw[Inv. Date].[Quartal]), 
            CALCULATE([Total Sales], 
                PARALLELPERIOD(raw[Inv. Date], -1, YEAR)
            ),
        ISINSCOPE(raw[Inv. Date].[Jahr]), 
            CALCULATE([Total Sales], 
                DATEADD(raw[Inv. Date], -1, YEAR)
            )
    )
RETURN
    IF(PREviousValue = 0, BLANK(), DIVIDE(CurrentValue - PREviousValue, PREviousValue))

 What I wanted to see is for instance for 2022 Qrts 2 - 3754.62.

Power_steffi_0-1680261187784.png

 

However, all these formulas return blank values, even though there is data available for the previous year.

 

Also the date is correcly transformed. 

Power_steffi_1-1680261250015.png

Power_steffi_2-1680261272457.png

Following other post, I could not find the solution for my problem. 

 

 

Can anyone suggest what might be causing this issue and how I can fix it? Any help would be greatly appreciated.

 

 

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @Power_steffi ,

 

I think you can try ALL() function in your calculation. Your measure should look like as below.

Sales Previous Year =
CALCULATE (
    [Total Sales],
    FILTER (
        ALL ( raw ),
        raw[Year]
            = MAX ( raw[Year] ) - 1
            && raw[Quarter] = MAX ( raw[Quarter] )
            && raw[Month] = MAX ( raw[Month] )
    )
)

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors