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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Budget previous year when no year is selected on filter

Hi,

 

I have a data that goes from 2008 to 2020 with real and Budget sales.

The client wants to see the current and last year budget while selects the year in a filter, like the image:

 

 budget.png

 

But the problem is when no year is selected; the image should show the sum of budget for all years and the budget for the previous year of the last year with data (not necessarily has to show budget for 2019). Am I explaining well?

 

budget2.png

I am using the following formula for previous year

BudgetPY = CALCULATE(SUM(FETS[BUDGET]);PREVIOUSYEAR(FETS[Year_Date]))

 

Then I tried to calculate the last year with data as the following:

YEAR_NOT_BLANK = CALCULATE(MAX(FETS[Year_Date]);(NOT(ISBLANK(FETS[BUDGET]))))

 

LASTYEAR_NOTBLANK = YEAR([YEAR_NOT_BLANK])-1

 

…and tried to use LASTYEAR_NOT_BLANK as a filter on the BudgetPY calculation but it does not work

 

Can enyone help me with this? Should be really simple

 

Many thanks

José

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi @Anonymous,

 

Share the link from where i can download your file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi, @Ashish_Mathur

 

Thanks for writing

 

The only thing I would like to have is MAX PREVIOUS YEAR when no filter is selected.

 

This DAX works (For MAX YEAR):

 

Budget = CALCULATE (

        SUM ( FETS[VALOR] );

        FILTER ( FETS; FETS[Year_Date] = MAX ( FETS[Year_Date] ) );NOT(ISBLANK(FETS[VALOR]))

    )

 

And for previous max year in trying to use

BudgetPY = CALCULATE (

        SUM ( FETS[VALOR] );

        FILTER ( FETS; FETS[Year_Date] = MAX ( FETS[Year_Date] )-1 );NOT(ISBLANK(FETS[VALOR]))

    )

 

Or

BudgetPY = CALCULATE (

        SUM ( FETS[VALOR] );

        FILTER ( FETS; FETS[Year_Date] = CALCULATE(MAX ( FETS[Year_Date] )-1 ));NOT(ISBLANK(FETS[VALOR]))

    )

 

And nothing is working. Can you help me please? What am I doing wrong?

 

Thank you very much

José

Hi,

 

It will help if you share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ImkeF
Community Champion
Community Champion

This measure should work:

 

BudgetPY =
IF (
    ISFILTERED ( FETS[Year_Date] ),
    CALCULATE ( SUM ( FETS[BUDGET] ), PREVIOUSYEAR ( FETS[Year_Date] ) ),
    CALCULATE (
        SUM ( FETS[BUDGET] ),
        FILTER ( FETS, FETS[Year_Date] = MAX ( FETS[Year_Date] ) )
    )
)

But in general it is not a good practice to operate without a separate calendar table.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Thank you very much Imkef

 

But the problem is that the max year does not have data, it is to say, my date range goes from 2008 to 2020, but the max year with budget data is 2016. When no year is selected on the filter I need to show the budget for 2016 dynamically (the latest year with data).

 

Thank you very much 🙂

ImkeF
Community Champion
Community Champion

It seems that I have a wrong understanding of your data structure. The example you've given used just one table "FETS": How are you running a Dates until 2020 in there without budget data? Are you using a separate calendar-table? 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi, yes I have one table FETS. The thing is in that table I have other values on the same column than budget, actually that column is called "Values" but I used the name Budget on the question just to simplify. There is another column called "Description" indicating that until 2020 should be budget data but for the moment the value is in blank.

ImkeF
Community Champion
Community Champion

You might consider clean up your data before moving on..

Otherwise please post sample data.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

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.