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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Parse Json and Model data

I have a sql table that contains Id, UserId and Data columns. The data column has value in json format.

Id column is 123, UserId column is rew1325Eb and the data column is

The json structure is as follows:

{

    "policydate": "2021-10-26",

    "candidates": [

        {

            "Fullname": "Luke Salvy",

            "income": {

                "basicSalary": 30000,

                "overtime": 100

            },

        {

            "Fullname": "Peter Rams",

            "income": {

                "basicSalary": 35000,

                "overtime": 200

        } 

    ]

}

The issues I'm facing is to have Candidates split to Candidate1, Candidate2 and so on if more candidate appears in the json in power BI.

 

for example:
Candidate1
Fullname = Luke Salvy
basicSalary = 30000
overtime = 100

 

Candidate2
Fullname = Peter Rams
basicSalary = 35000
overtime = 200

 

This is for forward calculation.
How can I achieve this in Power BI

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , You JSON has some problem , it should be like this

{

    "policydate": "2021-10-26",

    "candidates": [

        {

            "Fullname": "Luke Salvy",

            "income": {

                "basicSalary": 30000,

                "overtime": 100

		}},

        {

            "Fullname": "Peter Rams",

            "income": {

                "basicSalary": 35000,

                "overtime": 200

        } } 

    ]

}

 

Power BI is generating write code for this

 

let
    Source = Json.Document(File.Contents("C:\Users\Amit.Chandak\Downloads\test.json")),
    #"Converted to Table" = Table.FromRecords({Source}),
    #"Expanded candidates" = Table.ExpandListColumn(#"Converted to Table", "candidates"),
    #"Expanded candidates1" = Table.ExpandRecordColumn(#"Expanded candidates", "candidates", {"Fullname", "income"}, {"candidates.Fullname", "candidates.income"}),
    #"Expanded candidates.income" = Table.ExpandRecordColumn(#"Expanded candidates1", "candidates.income", {"basicSalary", "overtime"}, {"candidates.income.basicSalary", "candidates.income.overtime"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded candidates.income",{{"policydate", type date}, {"candidates.Fullname", type text}, {"candidates.income.basicSalary", Int64.Type}, {"candidates.income.overtime", Int64.Type}})
in
    #"Changed Type"
Anonymous
Not applicable

Yes, it generate the M query from the JSON as shown

EalTim_0-1636385946721.png

But how to split candidates with their respective income. For example , Luke Salvy is the Main applicant while Peter Rams is Additional applicant. I want to split them so I can calculate their individual tax Band later

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.