Tie list value to a record

Hi @sam.mckay,
I have a list of values coming from an API call representing the trend of a fund, which information is in a record. I need to tie the information for that fund with the values coming from the list returning from the same API call. It’s a free API service from India Mutual Fund API and I’m issuing just for just a fund, but I will add some other.
I thought I could add columns date and value to the columns containing the fund information like in the outcome excel file, or maybe better two tables, one would be a dimension for funds and the other with the historical values.

How can I do that?

Thanks for your very appreciated help

Roberto

funds.pbix (106.6 KB)
outcome.xlsx (35.6 KB)

@Roberto Is the Excel file correct? It shows only one row for 144838, but you have multiple entries from one Scheme in Power BI.

Hi @AntrikshSharma
my bad. The potential desired outcome it made by the information of the fund (the record) repeated for all the values in the list.

Thanks

Roberto

outcome.xlsx (33.8 KB)

@Roberto I am not sure what columns names are supposed to be so I leave that to you:

funds.pbix (117.2 KB)

Now you can create dimensions out of it on your own.

let
    Source = Json.Document ( Web.Contents ( "https://api.mfapi.in/mf/144838" ) ),
    data = Source[data],
    ConvertedtoTable = Table.FromList (
        data,
        Splitter.SplitByNothing(),
        null,
        null,
        ExtraValues.Error
    ),
    ExpandedColumn1 = Table.ExpandRecordColumn (
        ConvertedtoTable,
        "Column1",
        { "date", "nav" },
        { "Column1.date", "Column1.nav" }
    ),
    RenamedColumns = Table.RenameColumns (
        ExpandedColumn1,
        { { "Column1.date", "Date" }, { "Column1.nav", "Value" } }
    ),
    FundInfoList = List.Transform ( Record.ToList ( Source[meta] ), ( row ) => Text.From ( row ) ),
    AddedCustom = Table.AddColumn (
        RenamedColumns,
        "Custom",
        ( CurrentRow ) =>
            let
                ToRecord       = Record.ToList ( CurrentRow ),
                InsertFundInfo = List.InsertRange ( ToRecord, 0, FundInfoList ),
                ToTable        = Table.FromList ( InsertFundInfo ),
                TransposeTable = Table.Transpose ( ToTable )
            in
                TransposeTable
    ),
    RemovedOtherColumns = Table.SelectColumns ( AddedCustom, { "Custom" } ),
    ExpandedCustom = Table.ExpandTableColumn (
        RemovedOtherColumns,
        "Custom",
        { "Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7" },
        { "Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7" }
    ),
    ChangedType = Table.TransformColumnTypes (
        ExpandedCustom,
        {
            { "Column1", type text },
            { "Column2", type text },
            { "Column3", type text },
            { "Column4", Int64.Type },
            { "Column5", type text },
            { "Column6", type date },
            { "Column7", type number }
        }
    )
in
    ChangedType
2 Likes

Hi @AntrikshSharma ,
thanks so much. I need to understand how you did it!

Regards

Roberto

@Roberto I basically made a list containing FundInfos and another list containing Date and Value, then I used List.InsertRange to append FundInfos list to the other List. After that just extracted values.

The row and CurrentRow keywords are used to access the currently iterated row of the table through a custom function which is denoted by ( row ) and ( CurrentRow ).

2 Likes

Hi @AntrikshSharma,
thanks for your explanation. I had never seen such an expression at row 21.

The most puzzling part is (row) => Text.From(row) used as transformation function argument of the List.Trasform. The operator => makes look it as a user-defined function call.
Is there any resource in Enterprise DNA to better understand it?
IMHO M has less visibility than DAX in eDNA. Every time I post a topic looking for help, you guys show wonderful solutions in M using functions I had never heard about. Maybe I’m just too much spoiled by self-writing code feature of PQ.

Thanks again

Roberto

@Roberto No problem, you can learn advanced M from this series by Ben.

https://bengribaudo.com/blog/2017/11/17/4107/power-query-m-primer-part1-introduction-simple-expressions-let

@AntrikshSharma that’s very kind of you!

1 Like