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

Can´t get the IF-statement to do what i want

Hi,

 

I would like to get the sum of the field "Value" for each year where the "Year" equals "ValueYear". But if "Year" is bigger than the biggest "ValueYear" then use "Value" from the rows with the biggest "ValueYear". So in this case below both 2021 and 2022 would show 506 as a result.


I tried this but it only triggers "FinnsEj"

SumValue =
VAR Finns = CALCULATE(SUMX('Meters', 'Meters'[Value]), FILTER('Meters', 'Meters'[ValueYear]= 'Meters'[Year]))
VAR FinnsEj = CALCULATE(SUMX('Meters', 'Meters'[Value]), FILTER('Meters', 'Meters'[ValueYear]= MAX('Meters'[ValueYear])))
RETURN
IF(SUMX('Meters', 'Meters'[Year]) > MAXX('Meters', 'Meters'[ValueYear]), FinnsEj, Finns)

 

Table: Meters

MeteryearpartValueYearValue
13372022H22021253
13372022H12021253
13372022H12019238
13372022H22019238
13372022H22017222
13372022H12017222
13372022H12020239
13372022H22020239
13372022H22018230
13372022H12018230
13372021H12021506
13372021H22021506
13372021H22019475
13372021H12019475
13372021H12017444
13372021H22017444
13372021H12020477
13372021H22020477
13372021H12018459
13372021H22018459

 

 Thanks in advance!

Br
Johannes


1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

Is this what you are looking for?

Screen Capture #920.png

View solution in original post

4 REPLIES 4
Ahmedx
Super User
Super User

Is this what you are looking for?

Screen Capture #920.png

Thanks for this tidy solution 😃

amitchandak
Super User
Super User

@JohannesM , if this is a column, then try like

 

a new column
SumValue =
VAR Finns = CALCULATE(SUMX('Meters', 'Meters'[Value]), FILTER('Meters', 'Meters'[ValueYear]= earlier('Meters'[Year])))
VAR FinnsEj = CALCULATE(SUMX('Meters', 'Meters'[Value]), FILTER('Meters', 'Meters'[ValueYear]= MAX('Meters'[ValueYear])))
RETURN
IF('Meters'[Year] > 'Meters'[ValueYear], FinnsEj, Fin)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi and thanks,

 

I tried it as a column but got some kind of total for every row. Also, I would like to have it as a measure instead of a new column if possible. But at this rate I would take a new column solution if that fixes things 😃

JohannesM_0-1682320681071.png

 

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.