powerbi - Create Power BI Web Query based on data table -
i using power bi desktop create web query stack overflow api. want obtain number of questions asked on stack overflow each user extracted prepopulated table of users in power bi.
so want this:
pre-populated users:
- 6231494
- user2
- user3
stackoverflow questions:
- 6231494: 5
- user2: 12
- user3: 10
here current code web query in advanced editor:
let source = json.document(web.contents("http://api.stackexchange.com/2.2/users/6231494/answers?order=desc&sort=activity&site=stackoverflow")), items = source[items], #"converted table" = table.fromlist(items, splitter.splitbynothing(), null, null, extravalues.error), #"expanded column1" = table.expandrecordcolumn(#"converted table", "column1", {"owner", "is_accepted", "score", "last_activity_date", "creation_date", "answer_id", "question_id"}, {"column1.owner", "column1.is_accepted", "column1.score", "column1.last_activity_date", "column1.creation_date", "column1.answer_id", "column1.question_id"}), #"expanded column1.owner" = table.expandrecordcolumn(#"expanded column1", "column1.owner", {"reputation", "user_id", "user_type", "profile_image", "display_name", "link"}, {"column1.owner.reputation", "column1.owner.user_id", "column1.owner.user_type", "column1.owner.profile_image", "column1.owner.display_name", "column1.owner.link"}) in #"expanded column1.owner" i need way set current hardcoded id (6231494) equal list of ids predefined user table
assume have users table column id number:
you can make few changes questions query turn custom function in power bi:
(id number) => let source = json.document(web.contents("http://api.stackexchange.com/2.2/users/" & text.from(id) & "/answers?order=desc&sort=activity&site=stackoverflow")), items = source[items] ... (id number) => added turn query function; , user id replaced text.from(id).
here renamed getquestions keep clear it's function:
you can add custom column invoke function:
expand , shall find columns original query:
and can work data results want (e.g. number of questions).






Comments
Post a Comment