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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
ruthe23
Frequent Visitor

Calculate only first 3 years of data.

I can't seem to get a way to evaluate and calculate my columns.  Let me explain.  I have Volume Data by Model that I started tracking in 2018.  Here's an few example of data. 

Model # Vol18  Vol19  Vol20  Vol21  Vol22  Vol23  Vol24  First 3Years 
A               -                 -       39,288   124,716     27,696     22,728  
B               -       42,354     29,116     41,620        4,932           384  
C               -                 -         23,758     18,474        1,974 
D               -                 -       25,228     30,482     22,104     12,440     12,422 
E               -                 -       40,832     65,132

0

   

 

what I need is to find the year that has the first volume data and then add the next 2 years after that.  That's what I want in the last column.  As you can see they don't necessarly start in the same year.  They may just be starting this year or the year prior and not always have 3 years to calculate or they may have 3 years of data where one of the years is a zero.  I can seem to get it started with evaluating looking for a zero if zero then move on and look at the next column.  Once I have a nonzero then I could put that into a variable but then I am not sure how to get the next 2.  or where to go from there.   Thanks!

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1715742394028.png

 

 

Jihwan_Kim_0-1715742361106.png

 

Sales total: = 
SUM( sales_fact[sales] )

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

Sales total first 3 years: = 
VAR _t =
    WINDOW (
        1,
        ABS,
        3,
        ABS,
        FILTER ( ALL ( year_dimension[year] ), [Sales total:] <> BLANK () ),
        ORDERBY ( year_dimension[year], ASC )
    )
RETURN
    IF (
        HASONEVALUE ( model_dimension[model_#] ),
        CALCULATE ( [Sales total:], KEEPFILTERS ( _t ) )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

ruthe23
Frequent Visitor

Now I need one step further.  Now that I have 

Sales total first 3 years:

How can I use that measure to calculate with?  I have a query with the same model #'s and a forecast value.  I want to get percent of forcast using this sales total.  It doesn't appear as an option when I create a new measure. 

 

View solution in original post

4 REPLIES 4
ruthe23
Frequent Visitor

Now I need one step further.  Now that I have 

Sales total first 3 years:

How can I use that measure to calculate with?  I have a query with the same model #'s and a forecast value.  I want to get percent of forcast using this sales total.  It doesn't appear as an option when I create a new measure. 

 

Hi,

Thank you for your message, but I am not sure if I understood your question correctly.
Could you please provide how the expected outcome looks like in the sample?

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1715742394028.png

 

 

Jihwan_Kim_0-1715742361106.png

 

Sales total: = 
SUM( sales_fact[sales] )

 

WINDOW function (DAX) - DAX | Microsoft Learn

 

Sales total first 3 years: = 
VAR _t =
    WINDOW (
        1,
        ABS,
        3,
        ABS,
        FILTER ( ALL ( year_dimension[year] ), [Sales total:] <> BLANK () ),
        ORDERBY ( year_dimension[year], ASC )
    )
RETURN
    IF (
        HASONEVALUE ( model_dimension[model_#] ),
        CALCULATE ( [Sales total:], KEEPFILTERS ( _t ) )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Perfect.  I was totally making things much harder for myself.  I am really new to Power BI and this really made me think of some new ways of doing things.  thanks!

 

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!