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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous202020
Regular Visitor

SUMX formula to iterate if specific conditions are met?

Hello, just recently started using Power BI and I'm stuck on how I can use it to extract information

DateIDTitle GenderFirst NameLast NameQualGradeDescriptionGradeValue
16-Mar-202112345MrMaleJohnDoeAFFail0
16-Mar-202212345MrMaleJohnDoeAFFail0
16-Mar-202312345MrMaleJohnDoeAFFail0
16-Mar-202412345MrMaleJohnDoeAPPass1
16-Mar-202512345MrMaleJohnDoeAFFail0
16-Mar-202612345MrMaleJohnDoeBFFail0

 

I have my table setup similar to this. I need to be able to write a formula that looks at the ID and the Qual, if they are the same then add up the Grade Value. And if the total grade value is 2 then it's a pass, anything less then it's a fail. Also I need to count it as 1 register for each Qual. Any help would be much appreciated, thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from HotChilli , please allow me to provide another insight: 
Hi  @Anonymous202020 ,

Here are the steps you can follow:

1. Create calculated column.

Test1 =
SUMX(
    FILTER(ALL('Table'),
    'Table'[ID]=EARLIER('Table'
[ID])&&'Table'[Qual]=EARLIER('Table'[Qual])),[GradeValue])
Test2 =
var _maxpdate=
MAXX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Qual]=EARLIER('Table'[Qual])&&[Grade]="P"),[Date])
var _maxnodate=
MAXX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Qual]=EARLIER('Table'[Qual])),[Date])
return
IF(
    [Test1]=2 && [Date]=_maxpdate,1,
IF(
    [Test1]<2&&[Date]=_maxnodate,1,0))

vyangliumsft_0-1727338762765.png

2. Create calculated table.

Table 2 =
var _table=
FILTER(
    'Table',[Test2]=1)
return
SUMMARIZE(
    _table,
    [ID],[Title],[Gender],[First Name],[Last Name],[Qual],
    "Grade",MAXX('Table',[Description]),
    "Grade Value",MAXX('Table',[Test1]))

3. Result:

vyangliumsft_1-1727338762768.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Thanks for the reply from HotChilli , please allow me to provide another insight: 
Hi  @Anonymous202020 ,

Here are the steps you can follow:

1. Create calculated column.

Test1 =
SUMX(
    FILTER(ALL('Table'),
    'Table'[ID]=EARLIER('Table'
[ID])&&'Table'[Qual]=EARLIER('Table'[Qual])),[GradeValue])
Test2 =
var _maxpdate=
MAXX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Qual]=EARLIER('Table'[Qual])&&[Grade]="P"),[Date])
var _maxnodate=
MAXX(FILTER(ALL('Table'),'Table'[ID]=EARLIER('Table'[ID])&&'Table'[Qual]=EARLIER('Table'[Qual])),[Date])
return
IF(
    [Test1]=2 && [Date]=_maxpdate,1,
IF(
    [Test1]<2&&[Date]=_maxnodate,1,0))

vyangliumsft_0-1727338762765.png

2. Create calculated table.

Table 2 =
var _table=
FILTER(
    'Table',[Test2]=1)
return
SUMMARIZE(
    _table,
    [ID],[Title],[Gender],[First Name],[Last Name],[Qual],
    "Grade",MAXX('Table',[Description]),
    "Grade Value",MAXX('Table',[Test1]))

3. Result:

vyangliumsft_1-1727338762768.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

HotChilli
Super User
Super User

What I'm saying is the Grade column in the expected results looks like the original 'description' column, it doesn't look like a new measure which looks at the 'Grade Value' column in the visual and assigns pass or fail.

My evidence is the last line which shows Grade Value 1 and 'pass'

Ah yes I get what you mean

DateIDTitle GenderFirst NameLast NameQualGradeDescriptionGradeValue
16-Mar-202112345MrMaleJohnDoeAFFail0
16-Mar-202212345MrMaleJohnDoeAPMerit Pass1
16-Mar-202312345MrMaleJohnDoeAFFail0
16-Mar-202412345MrMaleJohnDoeAPPass1
16-Mar-202512345MrMaleJohnDoeAFFail0
16-Mar-202612345MrMaleJohnDoeBFFail0
16-Mar-202154321MrMalePhilReedAFFail0
16-Mar-202254321MrMalePhilReedAFFail0
16-Mar-202354321MrMalePhilReedAFFail0
16-Mar-202454321MrMalePhilReedAPDistinction1
16-Mar-202554321MrMalePhilReedAFFail0
16-Mar-202554321MrMalePhilReedBPPass1

 

Sorry I forgot to include the different types of passes you can get.

HotChilli
Super User
Super User

Thanks for the data - that is better than 99% of the posts on the forum (sorry, other posters).

So you want a table visual with the first 6 fields from the data table. Grade Value looks like an ordinary SUM aggregation on the field.

I don't understand the 'grade' column. Is it the Description column from the table? In which case, fine I think the expected output is achieved. However, I don't think the requirement:

" if the total grade value is 2 then it's a pass, anything less then it's a fail"  has been addressed.

Thoughts?

I was thinking I could have the Grade column read the value of the Grade Value in the new table and then give a Pass or Fail.

HotChilli
Super User
Super User

Calculated column(s) or measure(s)?

If it's a measure, please show the expected output.

--

I think the test data should be expanded to include a) another ID b) some data that adds up to 2 otherwise there's no 'pass'

I have expanded the table

DateIDTitle GenderFirst NameLast NameQualGradeDescriptionGradeValue
16-Mar-202112345MrMaleJohnDoeAFFail0
16-Mar-202212345MrMaleJohnDoeAPPass1
16-Mar-202312345MrMaleJohnDoeAFFail0
16-Mar-202412345MrMaleJohnDoeAPPass1
16-Mar-202512345MrMaleJohnDoeAFFail0
16-Mar-202612345MrMaleJohnDoeBFFail0
16-Mar-202154321MrMalePhilReedAFFail0
16-Mar-202254321MrMalePhilReedAFFail0
16-Mar-202354321MrMalePhilReedAFFail0
16-Mar-202454321MrMalePhilReedAPPass1
16-Mar-202554321MrMalePhilReedAFFail0
16-Mar-202554321MrMalePhilReedBPPass1

 

The expected output would be something like this 

IDTitleGenderFirst NameLast NameQualGradeGrade Value
12345MRMaleJohnDoeAPass2
54321MRMalePhilReedAFail1
12345MR MaleJohn DoeBFail0
54321MRMalePhileReedBPass1

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.