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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
lemaribdb
Helper II
Helper II

Last non blank month with context issues

Hi!
I have issue with below measure. It works when there are no additional columns that would "break down" the Actual/Plan/Forecast measure. But as soon as there is such column together in the matrix with below, the values are wrong.

I've noticed it's because the NO(ISBLANK()) gets evaluated separately for every "category" it's broken down into, instead on the whole measure. Below is the representation what the measure does. .

 

YearPeriodJob CategoryRaw AmountLastNonBlankPeriod
202311Finance511
202311Sales1012
202312FinanceBLANK()11
202312Sales1112

Because Finance is BLANK in 2023, it takes period 11 into account for this specific category. Where my goal is it should always be 12 in below case as there are some values for period 12.
And my values from below measure, if I remove period split will be: Finance 5, Sales 11. Instead of Finance 0, Sales 11

How can I fix the measure?

 

Headcount Switch Yearly = 
SUMX(
    VALUES('X_Calendar Period'[F_YEAR]),
    VAR CurrentYear = 'X_Calendar Period'[F_YEAR]
    VAR LastActualsPeriod = 
        CALCULATE(
            MAX('X_Calendar Period'[F_YEAR_MONTH_NO]),
            FILTER(
                ALL('X_Calendar Period'),
                'X_Calendar Period'[F_YEAR] = CurrentYear &&
                NOT(ISBLANK([Headcount By Heads]))
            )
        )
    VAR LastForecastPeriod = 
        CALCULATE(
            MAX('X_Calendar Period'[F_YEAR_MONTH_NO]),
            FILTER(
                ALL('X_Calendar Period'),
                'X_Calendar Period'[F_YEAR] = CurrentYear &&
                NOT(ISBLANK([FCST Headcount By Heads]))
            )
        )
    VAR LastPlanPeriod = 
        CALCULATE(
            MAX('X_Calendar Period'[F_YEAR_MONTH_NO]),
            FILTER(
                ALL('X_Calendar Period'),
                'X_Calendar Period'[F_YEAR] = CurrentYear &&
                NOT(ISBLANK([PLAN Headcount By Heads]))
            )
        )
    RETURN
    SWITCH(
        TRUE(),
        CurrentYear <= [Actuals Year], CALCULATE([Headcount By Heads], 'X_Calendar Period'[F_YEAR_MONTH_NO] = LastActualsPeriod),
        CurrentYear = [Forecast Year], CALCULATE([FCST Headcount By Heads], 'X_Calendar Period'[F_YEAR_MONTH_NO] = LastForecastPeriod),
        CurrentYear = [Plan Year], CALCULATE([PLAN Headcount By Heads], 'X_Calendar Period'[F_YEAR_MONTH_NO] = LastPlanPeriod),
        BLANK()
    )
)

 

 

 

 


 

2 REPLIES 2
some_bih
Super User
Super User

Hi @lemaribdb I do not have enought information from your side about model and relatioship so it is hard to spot issue/s.

Still, just based on your measure provided, I would focus on part

CurrentYear = 'X_Calendar Period'[F_YEAR] and try CurrentYear = SELECTEDVALUE('X_Calendar Period'[F_YEAR])

 

Another area to check soomething is your measures, not listed in your post, like [FCST Headcount By Heads] etc.

But, back to your issue if I understand correctly: you only want to figure out what is the latest available data for your  different "planned" periods, like last forecast period. If yes, and in your model there is Calendar / Date table connected to other "planned" periods with relationships, then your request should be simple find max of that "planned" periods data?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Anonymous
Not applicable

Hi @lemaribdb ,

 

It's not quite clear what your arithmetic logic is, but you could try changing not isblank to <>blank(). Since isblank returns a boolean value, and you're using &&, it will probably be judged as “both true”.

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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