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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
lily99
Regular Visitor

API call a list in M query

Hello,

I want to build a Body of a REST API call using M Query in PowerBI. 

I have a list of ID from a list named "UserID" that I want to use it as a variable in the body

 

Here is my script

body = "{""ids"":" & List.Distinct(UserID) & "}",

 

When I executed it, it gave me an errors:

Expression.Error: We cannot apply operator & to types Text and List.
Details:
Operator=&
Left={"ids":
Right=[List]

 

How can I handle this error? what can be a workaround?

 

Thanks for your help.

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

@lily99 , you might want to try

body = "{""ids"":[" & Text.Combine(List.Transform(List.Distinct(UserID), each """" & _ & """"),",") & "]}"

Screenshot 2021-02-05 050430.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

4 REPLIES 4
lily99
Regular Visitor

Hello @ImkeF 

Thanks for your suggestion, I applied it.

body = "{""ids"":[""" & Text.Combine(List.Distinct(UserID),",") & """]}"

 

and get the result

{"ids":["User1,User2,User3,User4"]}

 

However, I want to have the result like this:

{"ids":["User1","User2","User3","User4"]}

 

so I applied  extra "" around the list

= "{""ids"":[" & Text.Combine({"""",List.Distinct(UserID),""""},",") & "]}"

and I got this error:

Expression.Error: We cannot convert a value of type List to type Text.
Details:
Value=[List]
Type=[Type]

 

How can I make my body return like this?

{"ids":["User1","User2","User3","User4"]}

 

Thanks alot 

CNENFRNL
Community Champion
Community Champion

@lily99 , you might want to try

body = "{""ids"":[" & Text.Combine(List.Transform(List.Distinct(UserID), each """" & _ & """"),",") & "]}"

Screenshot 2021-02-05 050430.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thanks so much @CNENFRNL . It worked perfectly!

ImkeF
Community Champion
Community Champion

Hi @lily99 ,

if you want to pass a string into the body, you'd have to transform the list into a string as well. Meaning, concatenate the values by comma for example:

 

body = "{""ids"":" & Text.Combine(List.Distinct(UserID), ",") & "}",


 

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors