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
Anonymous
Not applicable

Help with JSON API import

This is my first time working with importing JSON and I'm somewhat new to PBi and could use some help please.

 

I have an API URL that was provided to me that pulls in quite a bit of data (fields) and I really only need two fields. I have asked, and the provider of the URL is unable to parse or do anything on his end other than provide me the URL so it's up to me to try to get the information I need...which is fine as it will teach me how to work with JSON import.

1)  I assume, to just narrow down the fields I need, I could right-click on the columns I don't need and click "Remove" correct?

2)  Of the two fields that are returned, one is called "endpoint_type" and is one of two values: "AGENT_TYPE_WORKSTATION" or "AGENT_TYPE_SERVER". I need to write a formula (DAX I assume) that will create a new column (so that I can tie this to a SKU column in another table to be something like this if(endpoint_type="AGENT_TYPE_WORKSTATION", "SECaaS - EPPAAS-D", "SECaaS - EPPAAS-S"). Is it as easy as that?

3) This one's  a little more difficult. The field that is being returned that I need is this part of the JSON which returns a list (first screen shot is the portion of the JSON, the second screen shot is the returned data in PBi). I can break out the list (third screen shot) but I get 1 of 3 values either

  1. WORKGROUP, customerNameWithExtraInfo
  2. customerName
  3. blank

I need to be able to, in case "a" retrieve just the customer name (which is equally difficult becuase it might be

  1. WORKGROUP, customerName.Non.domain.joined
  2. WORKGROUP, customerName.domain.joined

Thus, I need to remove WORKGROUP and remove Non.domain.joined or domain.joined. I realize this will probably be some nested IF statements, but if someone could help point me in the direction of how to write that in PowerQuery Editor I would be forever indebted. 

 

Thank you SO much,

Rob

 

FIRST SCREENSHOT

rob002.png

 

SECOND SCREENSHOT

rob001.png

THIRD SCREENSHOT

rob004.png

3 REPLIES 3
Anonymous
Not applicable

@PhilipTreacy  & @v-eqin-msft 

 

Philip - thank you SO much for your detailed explanation. I'm somewhat new to Power BI. I had some health issues which took me away from work - I'm going to look at this this week and I'll either follow-up with some clarifications or close as solved. I cannot thank you enough!

v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

Could you tell me if your problem has been solved by @PhilipTreacy 's method? If it is, kindly Accept it as the solution. More people will benefit from it.

 

Best Regards,
Eyelyn Qin

PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

1) When you refer to 'field' do you mean a column?  If so then yes, you can click on the column header and then press Delete.

 

2) This would be written in M (Power Query's language).  DAX is written in Power BI, not the Power Query editor.  You can add a Custom Column (Ribbon : Add Column -> Custom Column) with code something like this

if Text.Contains([endpoint_type] , "WORKSTATION") then "SECaaS - EPPAAS-D" else "SECaaS - EPPAAS-S"

 

3) You can use a series of Replace values steps to get the Customer Name.  Right click the Column headre and then click on Replace Values.  By replacing WORKSTATION, , Non.domain.joined and then .domin.joined with nothing, you are left with the Customer Name.

 

Here's the entire code using my sample data

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if Text.Contains([endpoint_type] , "WORKSTATION") then "SECaaS - EPPAAS-D" else "SECaaS - EPPAAS-S"),
    #"Replaced Value" = Table.ReplaceValue(#"Added Custom","WORKGROUP,","",Replacer.ReplaceText,{"group_name"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",".Non.domain.joined","",Replacer.ReplaceText,{"group_name"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1",".domain.joined","",Replacer.ReplaceText,{"group_name"})
in
    #"Replaced Value2"

 

Download my sample Excel workbook to see how this works. The PQ code works the same in Power BI.

 

Start Table

rsear1.png

 

End Table

rsear2.png

 

If you have issues adapting my code to your real data, please post some of your own sample data here, it's almost always better to provide data than screenshots.

 

regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.

Top Solution Authors