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
Anonymous
Not applicable

Extract multiple dates as rows from JSON field

Hello PowerBI community, 

 

I could not find an answer anywhere on the forum, I am trying to extract dates and an associated values from a JSON field. For each row, I have one or muliple dates with a value attributed to each date. I would like to transform them into a table with 2 columns "Date" and "Value". Could you please help?  

 

You can find below how the data looks like, I would like to transform it to have it in format: 

 

Date  Value

2021-10-27  21.25

2021-02-13  7.0833333333

2021-03-13  7.0833333333

2021-04-13  7.0833333333

etc.

 

jmasson_0-1635515594131.png jmasson_1-1635515612569.png

 

Thank you in advance!

 

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download new sample PBIX file

 

OK, you can extract the date and corresponding value using this query instead

 

let
    Source = { [#"2021-02-13" = 7.08333333], [#"2021-03-13" = 7.08333333], [#"2021-04-13" = 7.08333333] },
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom1" = Table.AddColumn(#"Converted to Table", "Date", each Record.FieldNames([Column1]){0}),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Value", each Record.Field([Column1], Record.FieldNames([Column1]){0}))
in
    #"Added Custom"

 

 

extractrec.png

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

4 REPLIES 4
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download new sample PBIX file

 

OK, you can extract the date and corresponding value using this query instead

 

let
    Source = { [#"2021-02-13" = 7.08333333], [#"2021-03-13" = 7.08333333], [#"2021-04-13" = 7.08333333] },
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom1" = Table.AddColumn(#"Converted to Table", "Date", each Record.FieldNames([Column1]){0}),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Value", each Record.Field([Column1], Record.FieldNames([Column1]){0}))
in
    #"Added Custom"

 

 

extractrec.png

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

This is brilliant, thank you so much @PhilipTreacy !

Anonymous
Not applicable

Hi @PhilipTreacy ,

 

Thanky ou for your answer. I tred that, but as I have more than 1000 different dates, I'm afraid all columns won't be created: 

 

jmasson_0-1635771345583.png

 

Will all the columns be created even I could not select them because I was limited to the 1st 1000 rows? 

 

Best,

Julien

 

PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download sample PBIX file with the following example.

 

If you have a column of Records you should be able to expand these using the double headed arrow in the column header

exprec.png

 

Which will give you something like this

unpivot.png

 

You can then unpivot the columns to give you this

unp1.png

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


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.