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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
clarkbj71
Helper I
Helper I

Calculate Sum by Product based on user selected year - 2 calculations: Sum before year and Sum After

I am stuck on a problem:  I am trying to calculate the sum of each product by a filter (user selected) year.  The two calculations I need are the sum of each product before the selected year and the sum of each product after and including selected year.  I need to see this data in a stacked bar chart.  I am also looking to do the same with counts.  These sums need to recalculate depending on what year the user selects for the filter on the report page.   Example.PNG

2 ACCEPTED SOLUTIONS
parry2k
Super User
Super User

@clarkbj71 try these measures:

 

Sum = SUM ( Table[Amount] )

Sum before selected year = 
VAR __selectedYear = SELECTEDVALUE ( SlicerTable[Year] )
RETURN
CALCULATE ( [Sum], Table[Year] < __selectedYear )


Sum after selected year = 
VAR __selectedYear = SELECTEDVALUE ( SlicerTable[Year] )
RETURN
CALCULATE ( [Sum], Table[Year] >= __selectedYear )

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

parry2k
Super User
Super User

@clarkbj71 better to do it in a title, make a big bold title. doing in a legend is not straightforward work. I'm planning to have a video on that part in the next few days as a workaround (subscribe to my YouTube channel, link below)

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@clarkbj71 better to do it in a title, make a big bold title. doing in a legend is not straightforward work. I'm planning to have a video on that part in the next few days as a workaround (subscribe to my YouTube channel, link below)

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

clarkbj71
Helper I
Helper I

That is awesome!  I will need to play around with it a bit more to make sure but I think that worked.   It also seems like it will be easy to recreate this for the counts as well.  Question, Is there a way to create a dynamic way to  show year selected in the chart? i.e. Sum after "2012"?   I could also do this in the title bar but would need it somehere on the graph so it is easy for folks to see what year the chart is currently referencing.Year selected.PNG

parry2k
Super User
Super User

@clarkbj71 try these measures:

 

Sum = SUM ( Table[Amount] )

Sum before selected year = 
VAR __selectedYear = SELECTEDVALUE ( SlicerTable[Year] )
RETURN
CALCULATE ( [Sum], Table[Year] < __selectedYear )


Sum after selected year = 
VAR __selectedYear = SELECTEDVALUE ( SlicerTable[Year] )
RETURN
CALCULATE ( [Sum], Table[Year] >= __selectedYear )

 

 

Follow us on LinkedIn and YouTube.gif to our YouTube channel

 

Learn about conditional formatting at Microsoft Reactor

My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.