Forum Discussion
Date parameter for filtering multiple tables
Hi Evereyone,
I have Dynamics NAV tables to join where some tables are imported from overseas. Because the internet connection over there is crappy i would like to dynamically filter the table (rows) based on a "From Date" parameter at the opening of the pbix file?
Ideally I would like to have a custom table with specific parameter values that are used in the filtering of other tables.
So i have a testtable like this:
let
Source = Excel.Workbook(File.Contents("C:\Temp\BITEST.xlsx"), null, true),
testTable_Sheet = Source{[Item="testTable",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(testTable_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"No_", Int64.Type}, {"Date", type date}, {"Description", type text}})
in
#"Changed Type"Which contains:
| No_ | Date | Description |
| 123 | 29-09-17 | test 123 |
| 124 | 03-10-17 | test 124 |
| 125 | 05-10-17 | test 125 |
And would like to have a Parameters Table with something like this:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcivKz3VJLElV0lEyMNQ1NNA1NFeKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Parameter = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Parameter", type text}, {"Value", type date}})
in
#"Changed Type"Which contains:
| Parameter | Value |
| FromDate | 01-10-17 |
How can I filter the first table to only import rows where the Date > Parameter.FromDate ?
Or maybe there are better solutions.
The actual tables contain 30+ columns and 400K+ rows and only need about 10% of that in my Dashboard.
Thanks in advance.
Colin
You can also use single parameters in PowerBI, but a table works just as fine in my eyes. So assume your parameter table is called "Parameters" this code should work:
let
Source = Excel.Workbook(File.Contents("C:\Temp\BITEST.xlsx"), null, true),
testTable_Sheet = Source{[Item="testTable",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(testTable_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"No_", Int64.Type}, {"Date", type date}, {"Description", type text}}) #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Date] >= Parameters{[Parameter="FromDate"]}[Value])) in #"Filtered Rows"Imke Feldmann
www.TheBIccountant.com -- How to integrate M-code into your solution -- Check out more PBI- learning resources here
2 Replies
- ImkeFCommunity Champion
You can also use single parameters in PowerBI, but a table works just as fine in my eyes. So assume your parameter table is called "Parameters" this code should work:
let
Source = Excel.Workbook(File.Contents("C:\Temp\BITEST.xlsx"), null, true),
testTable_Sheet = Source{[Item="testTable",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(testTable_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"No_", Int64.Type}, {"Date", type date}, {"Description", type text}}) #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Date] >= Parameters{[Parameter="FromDate"]}[Value])) in #"Filtered Rows"Imke Feldmann
www.TheBIccountant.com -- How to integrate M-code into your solution -- Check out more PBI- learning resources here
- pbinewbFrequent Visitor
Hi Imke,
Thanks for your solution.
Its works, so now i can extend the Parameters table with additional filters.
Beginning to see the advantages of PowerBI.