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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
SuperCal99
Helper I
Helper I

DAX - SUM IF Query

Hi there,

 

I have a table visual which i am trying to create a dax measure for.

Basically I have the below table. I want to sum the values in  [London] if:

[year] is 2022 and [statecodename] is active
[year] is 2023 and [statecodename] is inactive
[year] is 2024 and [statecodename] is inactive

So when i use my year filter , the table visual will update the sums based on the year selected

 

Hope that makes sense, please let me know if you need any further info

 

Many thanks

 

Cal

 

 

SuperCal99_1-1644003464423.png

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@SuperCal99 You should be able to use SUMX or CALCULATE to do this like:

Measure =
  VAR __2022 = CALCULATE(SUM([London]),[year] = 2022, [statecodename] = "active")
  VAR __2023 = CALCULATE(SUM([London]),[year] = 2023, [statecodename] = "inactive")
  VAR __2024 = CALCULATE(SUM([London]),[year] = 2024, [statecodename] = "inactive")
RETURN
  __2022 + __2023 + __2024

or

Measure =
  VAR __2022 = SUMX(FILTER('Table',[year] = 2022 && [statecodename] = "active"),[London])
  VAR __2023 = SUMX(FILTER('Table',[year] = 2023 && [statecodename] = "inactive"),[London])
  VAR __2024 = SUMX(FILTER('Table',[year] = 2024 && [statecodename] = "inactive"),[London])
RETURN
  __2022 + __2023 + __2024


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
SuperCal99
Helper I
Helper I

Thank you @Greg_Deckler, perfection

Greg_Deckler
Community Champion
Community Champion

@SuperCal99 You should be able to use SUMX or CALCULATE to do this like:

Measure =
  VAR __2022 = CALCULATE(SUM([London]),[year] = 2022, [statecodename] = "active")
  VAR __2023 = CALCULATE(SUM([London]),[year] = 2023, [statecodename] = "inactive")
  VAR __2024 = CALCULATE(SUM([London]),[year] = 2024, [statecodename] = "inactive")
RETURN
  __2022 + __2023 + __2024

or

Measure =
  VAR __2022 = SUMX(FILTER('Table',[year] = 2022 && [statecodename] = "active"),[London])
  VAR __2023 = SUMX(FILTER('Table',[year] = 2023 && [statecodename] = "inactive"),[London])
  VAR __2024 = SUMX(FILTER('Table',[year] = 2024 && [statecodename] = "inactive"),[London])
RETURN
  __2022 + __2023 + __2024


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.