![110d5278875f5c51625353c3fd5db46d.jpg](https://quantinsightsnetwork.com/wp-content/uploads/2023/12/110d5278875f5c51625353c3fd5db46d-678x307.jpg)
Welcome back to this week’s edition of the Power BI
blog series. This week, we link the M parameters to tables and
reference them in a slicer.
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image0-1659099200.png/110d5278875f5c51625353c3fd5db46d.jpg)
Microsoft have
added support recently for Power BI datasets added that have Dynamic M Query Parameters defined. Now, we may
create a composite model on such datasets to enrich or extend them. With Dynamic M Query Parameters, we can
let report viewers use filters or slicers to set values for an M query
parameter.
Last time, we
created parameters and amended an M query to reference the parameters:
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image1-1659099300.png/70198f3a4cbc07ced134fb64165e743a.jpg)
This week, we will create
a table with a column that provides the possible values available for that
parameter. This will allow the
parameters to be dynamically set based on filter selection. In this example, we want our StartTime parameter
and EndTime parameter to be dynamic. Since these parameters require a Date/Time
parameter, we want to generate date inputs that may be used to set the date for
the parameter. We start by creating a
new table in Power BI:
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image2-1659099328.png/0fab683383ac48a4fe55ff76b8ac0204.jpg)
Here’s the DAX to create the first table for the values for StartTime parameter:
StartDateTable
= CALENDAR (DATE(2016,1,1), DATE(2016,12,31))
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image3-1659099354.png/918c5a8795caab02cb28cab88296e06d.jpg)
This is the DAX for
the second table created for the values for EndTime parameter:
EndDateTable
= CALENDAR (DATE(2016,1,1), DATE(2016,12,31))
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image4-1659099382.png/c97edcd93be98e47ef314448ed526930.jpg)
We use a different
column name that is not in a table. Otherwise, if names are duplicated, the
selected value will be applied as a filter to the query.
Now that the tables
with the Date field have been created, we can bind each field to a
parameter. Binding the field to a
parameter essentially means that as the selected value for the field changes,
the value will get passed to the parameter and update the query where the
parameter is referenced. Therefore, to
bind field, we go to the Modeling (sic) tab, select the newly created
field, and then go to the Advanced properties (noting that the column ‘Data Type’
should match with the M parameter type):
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image5-1659099401.png/d6673b838437ea15e10550df6cb29ea3.jpg)
We select the
dropdown under ‘Bind to parameter’ and select the parameter that we want to
bind to the field:
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image6-1659099420.png/5c16a26dd3c3d99918a1f080ffd0bbd5.jpg)
Since this example
is for a single-select value (setting the parameter to a single value), we want
to keep Multi-select set to No, which is the default:
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image7-1659099437.png/b71603620bdffed728c758eb584e3a36.jpg)
If we were creating
an example that required multi-selection (passing multi-values to a single
parameter), then we would toggle the switch to Yes and ensure that our M query was set up properly to accept multiple values in the M query. Here’s an example for RepoNameParameter,
which allows for multiple values:
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image8-1659099454.png/df2ae2bfac53786b9d0313c5eaf2c314.jpg)
We repeat these
steps for other fields to bind to other parameters:
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image9-1659099472.png/f5961af3cf5bf737a7947d7ee97f88e5.jpg)
Finally, we can
reference this field in a slicer or as a filter:
![](https://sumproduct-4634.kxcdn.com/img/containers/main/./image10-1659099495.png/4e9daa595cb6ad7e8c1bc32be8428892.jpg)
If the mapped
column is set to No for Multi-select, we either use a single select mode in the
slicer or use a single select in the Filter card.
There are
additional steps if we want end users to be able to use the ‘Select all’ option
in the Slicer or Filter card, which we will look at next time.
Check back next week for more Power BI tips
and tricks!
Be the first to comment