web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Power BI iteration

(0) ShareShare
ReportReport
Posted on by

In power BI, I would like to iterate a list of values which are returned by a web service as Json object.

I have the query as follow:

let


Source = Json.Document(Web.Contents("xyz.api.crm5.dynamics.com/.../incidents")),


value = Source[value],
count = List.Count(value),
value1 = value{0},
value2 = value1[NRIC_x002e_governmentid]

in
value2

---

The web service will return list of data, how can I loop thru the data, currently I put a "0" in the index for value1=value{0} to get the 1st value, however if there're a lot of data, how can I iterate the data to retrieve all the values.

Please advise, thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Kentan,

    You could use the List.FirstN function to retrieve the same.

    List.FirstN(value,count)

    See: msdn.microsoft.com/.../mt253620.aspx

  • Community Member Profile Picture
    on at

    let

    Source = Json.Document(Web.Contents("xyz.api.crm5.dynamics.com/.../incidents")),

       value = Source[value],

       count = List.Count(value),

       value1 = List.FirstN(value, count),  

       value2 = value1[NRIC_x002e_governmentid]

    in

       value2

    ---  

    I got an error :

    Expression.Error: We cannot apply field access to the type List.

    Details:

       Value=List

       Key=NRIC_x002e_governmentid

    ---

    I am wondering how come I couldn't getthe specified field: "NRIC_x002e_governmentid"

    Any advice? Thanks.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Kentan,

    Please share the result you are getting when using the query below.

    let
    Source = Json.Document(Web.Contents("xyz.api.crm5.dynamics.com/.../incidents")),
       value = Source[value],
       count = List.Count(value),
       value1 = List.FirstN(value, count)
    in
       value1

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi,

    I got a list as shown,

    7532.powerBI2.PNG

    And when I click the record, I get a list of fields data

    7532.powerBI2.PNG

    I only want the NRIC_x002e_governmentid.

    Please advise, thanks.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi,

    Try the below code.

    let
    Source = Json.Document(Web.Contents("xyz.api.crm5.dynamics.com/.../incidents")),
       value = Source[value],
       count = List.Count(value),
       value1 = List.FirstN(value, count)
       value2 = value1({0.. count})[NRIC_x002e_governmentid]
    in
       value2

    Hope this helps.

  • Verified answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Kentan,

    You could do the same in the UI.

    1. Right click on the List heading in yellow colour. Select To Table option in that dropdown.
      2146.2.PNG
    2. A window appears as follows. Click OK.
      2146.2.PNG
    3. A new table of records will be displayed as shown below. Click on the icon marked in red.
      1588.3.PNG
    4. In the dropdown that comes, select the column NRIC_x002e_governmentid.
    5. Now you will get the list of all NRIC_x002e_governmentids of all the records.

    You could also use the code below.

    let
    Source = Json.Document(Web.Contents("xyz.api.crm5.dynamics.com/.../incidents")),
       value = Source[value],
       #"Converted to Table" = Table.FromList(value , Splitter.SplitByNothing(), null, null, ExtraValues.Error),
       #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"NRIC_x002e_governmentid"}, {"Column1.NRIC_x002e_governmentid"}) 
    in 
    #"Expanded Column1"

    Hope this helps.

  • Community Member Profile Picture
    on at

    Hi, 

    Thanks for helping, however I got the following error:

    powerBI3.PNG

    Any clues? Thanks.

  • Nithya Gopinath Profile Picture
    17,078 on at

    Hi Kentan,

    Please refer my above thread. It clearly explains how to convert the list to a table and get the column of that table.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    Great! I got the value I want.

    Thanks for the advice.

  • Nithya Gopinath Profile Picture
    17,078 on at

    Hi Kentan,

    If you got the answer, please close the thread as verified so that it can be helpful for others too.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans