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
Arthur_NS
Helper I
Helper I

Evolution with condition

Hi all,

 

I have a pretty straightforward table with 3 columns:

Year | Number of sales | YOY

 

Basically what I would like to do is calculate the YoY evolution of sales.

The only twist is that when the Year selected is 2022, then only rows with "Yes" in column YOY should be considered.

Any idea how to construct this DAX formula?

Thanks a lot,

Arthur

13 REPLIES 13
Arthur_NS
Helper I
Helper I

Sorry but I still get the same

@Arthur_NS is it possible for you to share PBIX file after removing sensitive data?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Hello,

 

The pbix file can be found here: https://drive.google.com/file/d/14ff94knR1CG59264cK6_B9oZBSl1Ini3/view?usp=sharing

 

Also a little explanation with my table, and the calculation I'm trying to get at

Arthur_NS_0-1646211038655.png

Thank you

Hi @Arthur_NS ,

 

Below code would give your ideal output:-

Measure = 
var selected_year = int(SELECTEDVALUE(Sheet1[Year]))

var _current_year_num = CALCULATE(SUM(Sheet1[Sales]),Sheet1[YoY]="YOY" && int(Sheet1[Year]) = year(TODAY()))
var _current_year_deno = CALCULATE(SUM(Sheet1[Sales]),all(Sheet1[Year]), Sheet1[YoY]="YOY" && int(Sheet1[Year]) =year(TODAY())-1)
var _current_year = DIVIDE(_current_year_num,_current_year_deno)-1

var _other_year_num = CALCULATE(SUM(Sheet1[Sales]),int(Sheet1[Year]) = int(selected_year))
var _other_year_deno = CALCULATE(SUM(Sheet1[Sales]),int(Sheet1[Year]) = int(selected_year)-1)
var _other_year = DIVIDE(_other_year_num,_other_year_deno)-1

return IF(selected_year = YEAR(TODAY()),_current_year,_other_year)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

That works great thanks a lot!

One last question, how would you handle the same situation but instead of Year you have a Season, so for example "2021/22", "2020/21" etc.
I guess in this case the formula that includes TODAY() wouldn't work?

@Arthur_NS With seasons do you have year column as well?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Yes I can add it to the database, but for one season there can be 2 different years as shown below.
Also, there might not be a 2022 in our database (latest year is 2021 in the table below)

 

Arthur_NS_1-1646219048262.png

 

 


@Arthur_NS wrote:

 

 

Arthur_NS_1-1646219048262.png

 

 


I think it is ok. For the table you provided, could you provide the result display you want to output? In order to understand your logic and requirements more clearly.

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Arthur_NS I think with the seasons like this, it will not work in this way. We should have some other column also as differentiater since multiple year fall in a season.

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Would you have an alternative solution for the Season scenario?
Thanks a lot

Arthur_NS
Helper I
Helper I

Thanks but I get this

 

Arthur_NS_0-1646062761717.png

 

@Arthur_NS try this:-

measure =
VAR selected_year =
    SELECTEDVALUE ( table[year] )
RETURN
    CALCULATE (
        SUM ( table[number of sales] ),
        FILTER ( table, int(table[year]) = int(selected_year) - 1 && table[YOY] = "Yes" )
    )

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Samarth_18
Community Champion
Community Champion

Hi @Arthur_NS ,

 

Please try this:-

 

measure =
VAR selected_year =
    SELECTEDVALUE ( table[year] )
RETURN
    CALCULATE (
        SUM ( table[number of sales] ),
        FILTER ( table, table[year] = selected_year - 1 && table[YOY] = "Yes" )
    )

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

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.