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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Vickram
Helper III
Helper III

loop through columns and add to counter

I have a table which contains multiple indicator columns and corresponding benchmark columns for each indicator. For example: each row in the table has ColA, BenchamarkA, ColB, BenchmarkB, ColC, BenchmarkC, ColD, BenchmarkD etc. I have all together 15 indicators and 15 benchmark values. I need to find a record which contains at least 3 or more indicator below benchmark values. Not sure how to achieve this.

 

is it possible to iterate through each column and comparing it with its benchmark value? If it is possible then I was thinking maybe we can create a measure whose value will be incremented by one if indicator found to be less than benchmark value while looping through the columns.

 

I am fairly new to Power BI, so need some assistance. Any help will be greatly appreciated.

1 ACCEPTED SOLUTION

HI  @Vickram 

Sorry for the late reply, 

for your data structure, you need to create a column as below:

Result = IF(
IF('Table'[ColA]<'Table'[BenchA],1,0)+
IF('Table'[ColB]<'Table'[BenchB],1,0)+
IF('Table'[ColC]<'Table'[BenchC],1,0)+
IF('Table'[ColD]<'Table'[BenchD],1,0)+
IF('Table'[ColE]<'Table'[BenchE],1,0)+
IF('Table'[ColF]<'Table'[BenchF],1,0)+
IF('Table'[ColG]<'Table'[BenchG],1,0)+
IF('Table'[ColH]<'Table'[BenchH],1,0)
>=3,"Fail","Pass")

 Result:

7.JPG

 

Regards,

Lin

Community Support Team _ Lin
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

6 REPLIES 6
amitchandak
Super User
Super User

@Vickram , Not very clear.

 

You have to create formula like this in Dax

 

If( [ColC]> [Benchmark C],1,0)

Sorry, my question was not much clear.

I am thinking of creating a new column. To calculate the value of this column, i need to to compare each of the 15 indicator column values to their corresponding benchmark values, and if any 3 of them are below their corresponding benchmark values, then I will update the new column values as "Failed", otherwise "Passed". As you can see, to flag it as "Failed", i need to compare all 15 indicator columns and count how many of them are below benchmark.

 

 If this is not clear enough, i will attach a sample data. Thanks in advance.

 

 

 

hi @Vickram 

Sample data and expected output would help tremendously.
Please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @ links,

Sample data is as below. "New column" in the table below is the result column I am expecting. Each ColA....ColH needs to be compared against corresponding BenchA...BenchH values. If any 3 Col values are less than Bench values then the company will be considered Fail, otherwise Pass. In below sample C1003 failed in 4 criteria and C1007 failed in 3, so they are tagged as "Fail" and rest as "Pass" in the New Column. Hope it makes sense.

CompanyNoColABenchAColBBenchBColCBenchCColDBenchDColEBenchEColFBenchFColGBenchGcolHBenchHNew Column
C1000100907870989548606055495599804530Pass
C1001979065701109555607855885594805230Pass
C100389907270949565605255655578804030Fail
C100499907570989562606555585589803530Pass
C1005749087701019572605555565582804230Pass
C100692907270979562605755575587803730Pass
C100785907870959559607055635583802830Fail

HI  @Vickram 

Sorry for the late reply, 

for your data structure, you need to create a column as below:

Result = IF(
IF('Table'[ColA]<'Table'[BenchA],1,0)+
IF('Table'[ColB]<'Table'[BenchB],1,0)+
IF('Table'[ColC]<'Table'[BenchC],1,0)+
IF('Table'[ColD]<'Table'[BenchD],1,0)+
IF('Table'[ColE]<'Table'[BenchE],1,0)+
IF('Table'[ColF]<'Table'[BenchF],1,0)+
IF('Table'[ColG]<'Table'[BenchG],1,0)+
IF('Table'[ColH]<'Table'[BenchH],1,0)
>=3,"Fail","Pass")

 Result:

7.JPG

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @Lin.

 

It does work.

 

As a workaround, I previosuly calculated the score for each benchmark, then finally use that score to determine "Pass" or "Fail". There were some NULLs (which became Blank after importing to Power BI), which I needed to use in my score calculation. I excluded the NULLs from the  calculation as they are "data not available". I will re-write the IF condidtion you provided to make sure that it excludes NULL from the comparision. 

 

Thanks again for your response.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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