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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Avian65
Helper I
Helper I

Calculate count depending on JSON Parsed data

Hello,

I am storing data in JSON in SharePoint list in following form for Level1 column. (Step 1)

parse1.JPG

 

 

 

 

 

 

After connecting with the the list in Excel PowerQuery, I did Parse Json and got the following result (Step 2)

parse2.JPG

 

Now I want to calculate count of OK, NA aor If any column haveing NG value. Iused following formula in excel (Step 3)

=COUNTIF(V2:AF2,"OK")

=COUNTIF(V2:AF2,"NA")

=COUNTIF(V2:AF2,"NG")

I ab able to get expected result as mentioned below in Excel.

 

parse3.JPG

 

 

 

 

I am able to do it all this in excel, without any issue, Now also able to produce Step1 and Step2 in PowerBI Query Editor, but struggling in Step3 PowerBI Query Editor. 

 

Please guide how can I calculate count of OK, NG, NA in PowerBI Query Editor.

Regards

Avian

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @Avian65 ,

The test table like this:

vyadongfmsft_0-1662542204836.png

 

Add an index column in Power Query:

vyadongfmsft_1-1662542353847.png

 

Select "index" column, and unpivot other columns:

vyadongfmsft_2-1662542454620.png

 

You will get a table like this:

vyadongfmsft_3-1662542593498.png

 

Please try following DAX in Power BI:

 

L1NA = 
var CountNA = CALCULATE(COUNT('Table'[Value]),FILTER('Table','Table'[Value] = "NA"))
return
IF(CountNA <> BLANK(),CountNA,0)

L1NG = 
var CountNG = CALCULATE(COUNT('Table'[Value]),FILTER('Table','Table'[Value] = "NG"))
return
IF(CountNG <> BLANK(),CountNG,0)

L1OK = 
var CountOK = CALCULATE(COUNT('Table'[Value]),FILTER('Table','Table'[Value] = "OK"))
return
IF(CountOK <> BLANK(),CountOK,0)

 

 

Create a table visual, you will get a result like in excel:

vyadongfmsft_4-1662542737246.png

 

Best regards,

Yadong Fang

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
v-yadongf-msft
Community Support
Community Support

Hi @Avian65 ,

The test table like this:

vyadongfmsft_0-1662542204836.png

 

Add an index column in Power Query:

vyadongfmsft_1-1662542353847.png

 

Select "index" column, and unpivot other columns:

vyadongfmsft_2-1662542454620.png

 

You will get a table like this:

vyadongfmsft_3-1662542593498.png

 

Please try following DAX in Power BI:

 

L1NA = 
var CountNA = CALCULATE(COUNT('Table'[Value]),FILTER('Table','Table'[Value] = "NA"))
return
IF(CountNA <> BLANK(),CountNA,0)

L1NG = 
var CountNG = CALCULATE(COUNT('Table'[Value]),FILTER('Table','Table'[Value] = "NG"))
return
IF(CountNG <> BLANK(),CountNG,0)

L1OK = 
var CountOK = CALCULATE(COUNT('Table'[Value]),FILTER('Table','Table'[Value] = "OK"))
return
IF(CountOK <> BLANK(),CountOK,0)

 

 

Create a table visual, you will get a result like in excel:

vyadongfmsft_4-1662542737246.png

 

Best regards,

Yadong Fang

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

Not able to open attachached PBIX, asking for excel.

Hi @Avian65 ,

If you can't open attached PBIX file, please update Power BI to the latest version and try again.

 

As for your other question, I think the solution is the same as I gave above.

 

Best regards,

Yadong Fang

I am able to open file without any error, but for other question. I am not able produce the table in following manner

LevelOKNGNA
Leve1522
Leve 2315

 

Regards

Avian

Thanks Fan for solution.

 

One question if I have another level that is L2 in same pattern and after calculation, I want to display table like below, how to display result as mentiond below.

 

LevelOKNGNA
Leve1522
Leve 2315
Greg_Deckler
Community Champion
Community Champion

@Avian65 You are going to want to unpivot those columns so that you end up with an Attribute and Value column where the Attribute is the column name and the Value is your OK, NG, etc. Then it is a simple matter for DAX or you could do a Group By using a count aggregation in Power Query.



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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.

Top Solution Authors
Top Kudoed Authors