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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Split rows mongodb

Hello everyone,

i have a collection in mongoDB that is something like this:

Print1.jpg


When i put this in power bi, i couldnt show the parcels name(like parcels 0,parcels 1,parcels 2....) in a column, what im expecting to do is something like this.( i didnt put all the fields that parcel object have in this example, i will put it in power bi)

Postigo_2-1621884437904.png

 

Is there someway to achieve something like this?

PowerBi File 

thanks

1 ACCEPTED SOLUTION
KNP
Super User
Super User

Hi @Anonymous, 

 

I think I understand. 

Does this achieve what you want?

let
  Source = Csv.Document(
    File.Contents("D:\Downloads\PowerBiFile\billingletters3.csv"), 
    [Delimiter = ",", Columns = 32, Encoding = 1252, QuoteStyle = QuoteStyle.Csv]
  ), 
  #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars = true]), 
  #"Changed Type" = Table.TransformColumnTypes(
    #"Promoted Headers", 
    {
      {"__v", Int64.Type}, 
      {"_id", type text}, 
      {"active", type logical}, 
      {"billingContacts", type text}, 
      {"changed", type datetime}, 
      {"closed", type logical}, 
      {"company._id", type text}, 
      {"company.cnpj", type text}, 
      {"company.name", type text}, 
      {"companyGroup._id", type text}, 
      {"companyGroup.name", type text}, 
      {"contacts", type text}, 
      {"cost.costCenter", Int64.Type}, 
      {"cost.executionUnity", Int64.Type}, 
      {"cost.natureType", type text}, 
      {"cost.observation", type text}, 
      {"cost.sellingValue", Int64.Type}, 
      {"cost.valueClass", Int64.Type}, 
      {"created", type datetime}, 
      {"info.costCenter", Int64.Type}, 
      {"info.executionUnity", Int64.Type}, 
      {"info.observation", type text}, 
      {"info.valueClass", Int64.Type}, 
      {"name", type text}, 
      {"owner._id", type text}, 
      {"owner.name", type text}, 
      {"parcels", type text}, 
      {"parcelsNumber", Int64.Type}, 
      {"products", type text}, 
      {"project", type text}, 
      {"projects", type text}, 
      {"refunds", type text}
    }
  ), 
  #"Parsed JSON" = Table.TransformColumns(#"Changed Type", {{"parcels", Json.Document}}), 
  #"Expanded parcels" = Table.ExpandListColumn(#"Parsed JSON", "parcels")
in
  #"Expanded parcels"

(you'll need to change the file path back)

 

Hope this helps.

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

i used the parse json in my ODBC connection and get this error message

Postigo_0-1621946181541.png

when i do the same thing in that csv file it works.

Postigo_1-1621946312269.png


anyone knows why this happens?

Are you able to paste the text from the parcels field in the previous step (mask/change any sensitive data)?

The error seems to be giving a fairly big clue where to look but difficult without seeing the data.

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
Anonymous
Not applicable

I will send the file, i exported a CSV from the collection.

Mongo Error 

I think you're running into an encoding issue because of the comma as a decimal separator.

This thread may help...

https://community.powerbi.com/t5/Desktop/Encoding/td-p/1021318 

 

You need to add column instead of transform and then add the optional encoding...

KNP_0-1622058322039.png

It still errors for me because of my regional settings but give it a try on your system to see if it works. If it does work I'd suggest testing it works when published to the service also as regional settings can sometimes be an issue there also (usually only tmezones though).

 

let
  Source = Csv.Document(
    File.Contents("D:\Downloads\MongoError (1)\data34.csv"), 
    [Delimiter = ",", Columns = 2, Encoding = 65001, QuoteStyle = QuoteStyle.None]
  ), 
  #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars = true]), 
  #"Changed Type" = Table.TransformColumnTypes(
    #"Promoted Headers", 
    {{"_id", type text}, {"parcels", type text}}
  ), 
  #"Inserted Parsed JSON" = Table.AddColumn(
    #"Changed Type", 
    "JSON", 
    each Json.Document([parcels], TextEncoding.Windows)
  )
in
  #"Inserted Parsed JSON"

 

I hope this works for you. 🤞

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
CNENFRNL
Community Champion
Community Champion

Use Json.Document() to parse each parcel.


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!

Anonymous
Not applicable

Thanks for your help, now i have somewhere to start!

KNP
Super User
Super User

Hi @Anonymous, 

 

I think I understand. 

Does this achieve what you want?

let
  Source = Csv.Document(
    File.Contents("D:\Downloads\PowerBiFile\billingletters3.csv"), 
    [Delimiter = ",", Columns = 32, Encoding = 1252, QuoteStyle = QuoteStyle.Csv]
  ), 
  #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars = true]), 
  #"Changed Type" = Table.TransformColumnTypes(
    #"Promoted Headers", 
    {
      {"__v", Int64.Type}, 
      {"_id", type text}, 
      {"active", type logical}, 
      {"billingContacts", type text}, 
      {"changed", type datetime}, 
      {"closed", type logical}, 
      {"company._id", type text}, 
      {"company.cnpj", type text}, 
      {"company.name", type text}, 
      {"companyGroup._id", type text}, 
      {"companyGroup.name", type text}, 
      {"contacts", type text}, 
      {"cost.costCenter", Int64.Type}, 
      {"cost.executionUnity", Int64.Type}, 
      {"cost.natureType", type text}, 
      {"cost.observation", type text}, 
      {"cost.sellingValue", Int64.Type}, 
      {"cost.valueClass", Int64.Type}, 
      {"created", type datetime}, 
      {"info.costCenter", Int64.Type}, 
      {"info.executionUnity", Int64.Type}, 
      {"info.observation", type text}, 
      {"info.valueClass", Int64.Type}, 
      {"name", type text}, 
      {"owner._id", type text}, 
      {"owner.name", type text}, 
      {"parcels", type text}, 
      {"parcelsNumber", Int64.Type}, 
      {"products", type text}, 
      {"project", type text}, 
      {"projects", type text}, 
      {"refunds", type text}
    }
  ), 
  #"Parsed JSON" = Table.TransformColumns(#"Changed Type", {{"parcels", Json.Document}}), 
  #"Expanded parcels" = Table.ExpandListColumn(#"Parsed JSON", "parcels")
in
  #"Expanded parcels"

(you'll need to change the file path back)

 

Hope this helps.

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors