Forum Discussion
Matrix with dynamic rows?
I've got a very small dataset (too small to post π) that contains just 3 tables:
Vehicles which contains two columns: Vehicle No. & Standard Department
| Vehicle | Standard Department |
| DTR-465 | COIL-ACE |
| DTR-466 | COIL-ACE |
| DTR-467 | COIL-ACE |
| DTR-468 | ACE-ATT |
| DTR-469 | ACE-ATT |
| DTR-470 | IBERICA |
Appointed Department which contains 4 columns: Vehicle No., From Date, Till Date, Appointed Department
| Vehicle | From | Till | Appointed Department |
| DTR-465 | 01/01/2020 | 31/01/2020 | ACE-ATT |
| DTR-465 | 01/02/2020 | 28/02/2020 | IBERICA |
| DTR-470 | 01/01/2020 | COIL-ACE |
Turnover which contains 2 columns: Vehicle No., Turnover.
| Vehicle | Turnover |
| DTR-465 | β¬ 200 |
| DTR-466 | β¬ 300 |
| DTR-467 | β¬ 250 |
| DTR-468 | β¬ 275 |
| DTR-469 | β¬ 315 |
| DTR-470 | β¬ 180 |
What i want to achieve is to create a matrix table and give the end user the possibilty to filter on a date, filtering my matrixtable immedately with the current correct info.
So if the user selects till 30/01/2020 he would get something like:
| Selection: | Selection: | |||||
| 30/01/2020 | 03/02/2020 | |||||
| Turnover | Turnover | |||||
| ACE-ATT | - | 790 | ACE-ATT | - | 590 | |
| DTR-465 | 200 | DTR-468 | 275 | |||
| DTR-468 | 275 | DTR-469 | 315 | |||
| DTR-469 | 315 | COIL-ACE | - | 930 | ||
| COIL-ACE | - | 730 | DTR-466 | 300 | ||
| DTR-466 | 300 | DTR-467 | 250 | |||
| DTR-467 | 250 | DTR-470 | 180 | |||
| DTR-470 | 180 | DTR-465 | 200 |
Any suggestions how to achieve this?
11 Replies
- amitchandakSuper User
Ashish_Mathur , would you be able to help on this?
- Ashish_MathurSuper User
Hi,
I do not understand your question. Vehicles DTR-466,467,468 and 469 have no record at all in the second table. Therefore, when one selects the date as 30/1/2020, why should these appear in the final result?
- BramSegersFrequent Visitor
Hi,
Thanks for your reply.
I indeed didn't mention that, but those vehicles should appear date-independant, because they have a registered turnover.
- AnonymousNot applicable
Refer to the table,
Vehicle From Till Appointed Department DTR-465 01/01/2020 31/01/2020 ACE-ATT DTR-465 01/02/2020 28/02/2020 IBERICA DTR-470 01/01/2020 COIL-ACE Here vehicle no DTR-465 is appointed to IBERICA department during the period from 01/02/2020 to 28/02/2020. Then why is vehicle no. DTR-465 appearing in department "COIL-ACE" in your example when the selected date is 03/02/2020?
I need clarification on this to arrive at the logic. Because when I tried the solution, following are the outputs I am getting in Power BI with date selections 30/01/2020 and 03/02/2020.
- AnonymousNot applicable
You may try the following solution. It is not an optimum solution, but a simple one to start with.
Step 1:
Add a calendar table to your data model. Select "New Table" and use the following DAX code.
Calendar = CALENDAR(DATE(2020,1,1),DATE(2020,2,29))Change the date ranges as per your requirement.
Step 2:
Add another calculated table to your data model. Select "New Table" and use the following DAX code.
VehicleCalendar = CROSSJOIN(Vehicles,'Calendar')Step 3:
Add two calculated columns to the "VehicleCalendar" table that you have added in Step 2.
Appointed Department = CONCATENATEX ( FILTER ( 'Appointed Department', AND ( AND ( 'Appointed Department'[From] <= VehicleCalendar[Date], 'Appointed Department'[TillDate] >= VehicleCalendar[Date] ), 'Appointed Department'[Vehicle] = VehicleCalendar[Vehicle] ) ), 'Appointed Department'[Appointed Department] )Relevant Department = IF ( ISBLANK ( VehicleCalendar[Appointed Department] ), VehicleCalendar[Standard Department], VehicleCalendar[Appointed Department] )Step 3a: Add another calculated column to the "Appointed Department" table.
TillDate = IF(ISBLANK('Appointed Department'[Till]),MAX('Calendar'[Date]),'Appointed Department'[Till])Step 4: Add a measure
Turnover = SUMX(Turnover,Turnover[Turnover])The relationships should be as follows...
Please pay attention to the Cardinality and Cross Filter Directions of the relationships
Step 5:
Add a date slicer to your data model using the "Date" field from the "Calendar" table.
Step 6:
Add a matrix visual and add the "Relevant Department" and "Vehicle" Columns from the table named "Vehicle Calendar" into the Rows of the matrix visual.
Step 7:
Add the measure named "Turnover " that we have created in Step 4 to the "Values" section of the matrix visual.
This will give the results as shown in my earlier post.
This may not be the most optimum solution, but once you do this, you will get started and you can further improvise.
- BramSegersFrequent Visitor
Thanks a lot for this help, really appreciated!!!
The one thing left is that we only have to look at the "Till" ("Tot") date to determine the "Department Appointed".
So for the below scenario, since 14/02/2020 is in the latest period, only IBERICA should be visible. Is this something we can achieve as well?
- AnonymousNot applicable
If you only need to select the till date only, then you can just change the date selector to "Drop Down" instead of "Between" as shown in the images below. Then set the "Single Select" property of the date slicer to true.