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
Anonymous
Not applicable

January month not comparing to December last year

Hey!

 

I finally managed to compare current month with previous month values, with a "YYYYMM" field 

Test = 
VAR CurrYM =
    MAX(Date[YearMonth])
VAR prevDate =
    DATE(LEFT(CurrYM, 4), RIGHT( CurrYM, 2) -1, 1)
VAR prevYM = 
    YEAR(prevDate) *100
        + MONTH(prevDate)
RETURN
    CALCULATE(
            [# Customers],
            FILTER(ALLSELECTED(Date), Date[YearMonth] = prevYM)
    )

 

The result however is that, when I want to only see current Year results (Customer differences between months). It shows that January has gained the total amount of customers. Cause there is no december, it probably thinks the previous month must be 0? 

Foxxon28_1-1627650395209.png

 

 This makes working with this measure unusable, since it makes the other months look tiny. Is there any way to make January look at the december results, despite me only wanting to see current year results? If I were to add last year results, the issue would move to january last year.

 

I'd love to hear what my options are :)!

 

Kind regards,

Daniël

1 REPLY 1
daxer-almighty
Solution Sage
Solution Sage

You're doing it all wrong.

 

When working with dates, you should never work with text and do stunts in the code like

DATE(LEFT(CurrYM, 4), RIGHT( CurrYM, 2) -1, 1)

It's not only ugly. It's error-prone. As you've seen.

 

Instead, you should work with real numbers/dates and, if possible, with the in-built time-intel functions. Please go to this vid and learn how to deal with date calculations:

 

(2) Time Intelligence calculations with Power BI | Community Webinars - YouTube

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.