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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
E_
Frequent Visitor

Calculate the total of each year

I'm trying to calculate the total of each year. 

The subrow 'Total of each row' is a simple count function that when I use the option 'Row subtotal' on the visual settings it returns the the total of each column on the row subtotals. 

The subrow 'Total of each year' is a function that I created to calculate this row subtotals for each year so later I can use it for other things.

 

But it is not returning the total I want for each column year (that are 124966 for 2023 and 16980 for 2024) but the total of everything that is 141946. 

The measure is the following: 


Total of each year = 

CALCULATE(
    COUNTA('Registration'[ID]),
    ALLSELECTED('Registration')
)

E__0-1712518917814.png

 

3 ACCEPTED SOLUTIONS
Wilson_
Super User
Super User

Hi E_,

 

If you check the documentation, you will see ALLSELECTED explicitly ignores your filters inside your visual.

 

Since you want to keep the year filter from the visual, try:

Total of each year = 
VAR SelYears = VALUES ( 'Calendar'[Year] )
VAR Result =
CALCULATE (
    COUNTA ( 'Registration'[ID] ),
    ALLSELECTED ( 'Registration' ),
    SelYears
)

RETURN Result


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.

 




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

Proud to be a Super User!





View solution in original post

E_
Frequent Visitor

Thank you so much for the help, I was struggling for weeks with this problem!!

Why does this SelYears let it keep the total of each year whe I use it in the calculate?

 

View solution in original post

E_,

 

Thanks for the update, glad that helped.

 

Essentially, storing the years in the variable keeps a memory of your visual's year filter. Then after you've ignored that original visual filter context by invoking ALLSELECTED, you are reapplying that original filter context on years to the calculation by putting the SelYears variable in a CALCULATE filter argument.

 

In short, ALLSELECTED ignores your years; saving the years in the variable and adding it to CALCULATE re-applies the years.

 

Let me know if that doesn't make sense. I will try to explain it differently. 🙂


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




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

Proud to be a Super User!





View solution in original post

3 REPLIES 3
E_
Frequent Visitor

Thank you so much for the help, I was struggling for weeks with this problem!!

Why does this SelYears let it keep the total of each year whe I use it in the calculate?

 

E_,

 

Thanks for the update, glad that helped.

 

Essentially, storing the years in the variable keeps a memory of your visual's year filter. Then after you've ignored that original visual filter context by invoking ALLSELECTED, you are reapplying that original filter context on years to the calculation by putting the SelYears variable in a CALCULATE filter argument.

 

In short, ALLSELECTED ignores your years; saving the years in the variable and adding it to CALCULATE re-applies the years.

 

Let me know if that doesn't make sense. I will try to explain it differently. 🙂


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




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

Proud to be a Super User!





Wilson_
Super User
Super User

Hi E_,

 

If you check the documentation, you will see ALLSELECTED explicitly ignores your filters inside your visual.

 

Since you want to keep the year filter from the visual, try:

Total of each year = 
VAR SelYears = VALUES ( 'Calendar'[Year] )
VAR Result =
CALCULATE (
    COUNTA ( 'Registration'[ID] ),
    ALLSELECTED ( 'Registration' ),
    SelYears
)

RETURN Result


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.

 




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

Proud to be a Super User!





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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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