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
sallywt
Regular Visitor

JSON data from a web service call

I conntect to a D3 database using a restful web service.  This returns data in the following format and I want to use this data to provide a visual report.

 

{
	"ordercount": {
		"OUT": [[			"29/08/2017",			"31/08/2017",			"01/09/2017",			"04/09/2017"
			],[			"6",			"6",			"1",			"3"
			],[			"15",			"6",			"1",			"4"
			]
			],	
		"IDOUT": 			""
	}
}

 

Can anyone advise how I can do this?  I can see the data but I'm not sure how all the fields can be included in a report.

1 ACCEPTED SOLUTION

Then this is your code:

 

let
    Source = Json.Document(File.Contents(...YourJsonFile...)),
    ordercount = Source[ordercount][orderList],
    orders = Table.FromRecords(ordercount[orders])
in
    orders

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

HI @sallywt,

 

ImkeF's solution seems well, I think you can also take a look at below article about how to get data from web api and format json data.
Can you use Power BI to call REST APIs and parse JSON?

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

I did some more work on the web service and now I have a lot more meaningful JSON coming out like below

 

{
	"ordercount": {
	"orderList": {
		"orders": [
				{
					"orderdates": "31/08/2017",
					"headerscount": "6",
					"linescount": "6"
				},
				{

This makes it much easier to handle as it is more meaningful. "orderdates": "01/09/2017", "headerscount": "1", "linescount": "1" }, { "orderdates": "04/09/2017", "headerscount": "3", "linescount": "4" } ] }, "IDOUT": "" } }

 

 

Then this is your code:

 

let
    Source = Json.Document(File.Contents(...YourJsonFile...)),
    ordercount = Source[ordercount][orderList],
    orders = Table.FromRecords(ordercount[orders])
in
    orders

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Having brough the data in through a web service call as the source connection and sorted out the format the data was coming in I have been able to convert it to a table and report on the data as I hoped I would.

 

Thank you to everyone for your help it is much appreciated. 

ImkeF
Super User
Super User

You need to transform this into a table with a date-column:

 

let
    Source = Json.Document(File.Contents("...PathToYourJson...")),
    OUT = Source[ordercount][OUT],
    ToTable = Table.FromColumns(OUT, {"Date", "Col1", "Col2"}),
    #"Changed Type" = Table.TransformColumnTypes(ToTable,{{"Date", type date}, {"Col1", type number}, {"Col2", type number}})
in
    #"Changed Type"

 You might want to adjust the names of the "value-columns" in step "ToTable" to meaningful names.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

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.