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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
SNPPowerbi
Regular Visitor

Dynamic Table Data Mapping !!

Hi,

 

I have mapping table, where tentant wise table & column values. I need to pull data as per the mapping table & columns to be populated on PowerBI

 

Any column removal/addition that should impact on report.

 

Sample Mapping Table

 

IDCol1Col2Col3Col4Col5Col6Col7Col7Col8Col9Col10
1Table1.col1Table1.col2Table1.col2Table3.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant1
2Table2.col1Table2.col1Table2.col1Table2.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant2
3Table1.col1Table1.col2Table1.col2Table3.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant3
4Table2.col1Table2.col1Table2.col1Table2.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant4
5Table1.col1Table1.col2Table1.col2Table3.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant5
6Table2.col1Table2.col1Table2.col1Table2.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant6
7Table1.col1Table1.col2Table1.col2Table3.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant7
8Table2.col1Table2.col1Table2.col1Table2.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant8
9Table1.col1Table1.col2Table1.col2Table3.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant9
10Table2.col1Table2.col1Table2.col1Table2.col4Table1.col3Table3.col6Table5.col2Table4.col4Table6.col2Table2.col1Tenatant10
1 REPLY 1
ImkeF
Community Champion
Community Champion

Hi,

this should do:

 

let

// You can copy this function code as a standalone-function as well
fnMappgingTable= (MappingTable, NameOfFilterColumn, FilterValue) =>
let
    Source = MappingTable,
    #"Filtered Rows" = Table.SelectRows(Source, each (Record.Field(_, NameOfFilterColumn) = FilterValue)){0},
    #"Converted to Table" = Record.ToTable(#"Filtered Rows"),
    #"Split Column by Delimiter1" = Table.SplitColumn(#"Converted to Table", "Value", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Value.1", "Value.2"}),
    #"Added Custom1" = Table.AddColumn(#"Split Column by Delimiter1", "Columns", each Expression.Evaluate("Table.Column("&[Value.1]&", """&[Value.2]&""")", #shared)),
    #"Removed Errors" = Table.RemoveRowsWithErrors(#"Added Custom1", {"Columns"}),
    Custom1 = Table.FromColumns(#"Removed Errors"[Columns])
in
    Custom1,
// End of function code

    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("zZA9CoAwDEbvkrmI/a/3cCsdqnQrden9UQMKgQ4uQsbHR8jjxQgSBKx5q0VO+1EpqTHpmwzZNNncQ5bcGXLnyKbe76XlnluXkESEwf6J/rZTaKeZttNoZ5i2M2hnmbazaOeYtnNo55m282gXmLYLaLcwbbegnZyZxrvEUjoB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, Col1 = _t, Col2 = _t, Col3 = _t, Col4 = _t, Col5 = _t, Col6 = _t, Col7 = _t, #"Col7 (2)" = _t, Col8 = _t, Col9 = _t, Col10 = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Result", each fnMappgingTable(Source, "Col10", [Col10]))
in
    #"Added Custom"

 

The full query above returns one table per row with the different columns from the different tables. Not sure how you actually want to integrate it into your solution, but of course you can also use the function on its own so that only one table will be returned.

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors