Forum Discussion
KPI Cards for Monthly Variance (with DAX filter)
Hi need, some help here. So I have a matrix table that shows the difference (lets call it "Distance") between Odometer Reading between Current month and previous month. The matrix used Table[Name] and Table[Vehicle Number] as rows. There are 2 tables on the visual, one has a visual filter for Table2[Profile] = 1, the second has Table[Profile] = 2. Table 2 has a 1 to Many relationship with Table 1 using NAME_DATE_KEY.
The DAX works fine but the issue is creating a DAX for a KPI Card to show the percentage of Distance for Table2[Profile] = 1 and Table2[Profile] = 2, and to make it dynamic so that the result shown on the cards are correct when date slicer are used on when Table[Name] or Table[Vehicle Number] is selected on the matrix table.
A couple of things to note is that its normal for some of the month difference to be negative especially if there was a mistake in current month input for Odometer or someone used 3 trucks last month and used used a truck this month.
| NAME_KEY | Date | DATE_KEY | Vehicle Number | Odometer Reading | YearMonth | NAME_DATE_KEY | Name | NAME_VEH_DATE_KEY |
| BATMAN | 01-Aug-24 | 8012024 | 35341 | 10,676 | Aug-24 | BATMAN2024-08 | Bat Man | BATMAN2752412024-08 |
| BATMAN | 01-Jul-24 | 7012024 | 35341 | 16,446 | Jul-24 | BATMAN2024-07 | Bat Man | BATMAN2752412024-07 |
| BATMAN | 01-Jun-24 | 6012024 | 35341 | 11,079 | Jun-24 | BATMAN2024-06 | Bat Man | BATMAN2752412024-06 |
| BATMAN | 01-May-24 | 5012024 | 35341 | 140,078 | May-24 | BATMAN2024-05 | Bat Man | BATMAN2752412024-05 |
| BATMAN | 01-Apr-24 | 4012024 | 35341 | 140,078 | Apr-24 | BATMAN2024-04 | Bat Man | BATMAN2752412024-04 |
| BATMAN | 01-Apr-24 | 4012024 | 3543RD | 4,634 | Apr-24 | BATMAN2024-04 | Bat Man | BATMAN2754212024-04 |
| BATMAN | 01-Mar-24 | 3012024 | 35341 | 135,262 | Mar-24 | BATMAN2024-03 | Bat Man | BATMAN2752412024-03 |
| BATMAN | 01-Feb-24 | 2012024 | 35341 | 126,447 | Feb-24 | BATMAN2024-02 | Bat Man | BATMAN2752412024-02 |
| BATMAN | 01-Jan-24 | 1012024 | 35114 | 169,965 | Jan-24 | BATMAN2024-01 | Bat Man | BATMAN2751142024-01 |
| SPIDERMAN | 01-Dec-23 | 12012023 | 35341 | 110,734 | Dec-23 | SPIDERMAN2023-12 | Spider Man | SPIDERMAN2752412023-12 |
| SPIDERMAN | 01-Nov-23 | 11012023 | 35341 | 104,795 | Nov-23 | SPIDERMAN2023-11 | Spider Man | SPIDERMAN2752412023-11 |
| SPIDERMAN | 01-Oct-23 | 10012023 | 35341 | 99,537 | Oct-23 | SPIDERMAN2023-10 | Spider Man | SPIDERMAN2752412023-10 |
| SPIDERMAN | 01-Oct-23 | 10012023 | 2561 | 4,763 | Oct-23 | SPIDERMAN2023-10 | Spider Man | SPIDERMAN2752412023-10 |
| SPIDERMAN | 01-Oct-23 | 10012023 | 32189 | 14,351 | Oct-23 | SPIDERMAN2023-10 | Spider Man | SPIDERMAN2752412023-10 |
| SPIDERMAN | 01-Sep-23 | 9012023 | 35341 | 93,313 | Sep-23 | SPIDERMAN2023-09 | Spider Man | SPIDERMAN2752412023-09 |
| SPIDERMAN | 01-Aug-23 | 8012023 | 35341 | Aug-23 | SPIDERMAN2023-08 | Spider Man | SPIDERMAN2752412023-08 | |
| SPIDERMAN | 01-Jul-23 | 7012023 | 35341 | 82,759 | Jul-23 | SPIDERMAN2023-07 | Spider Man | SPIDERMAN2752412023-07 |
| SPIDERMAN | 01-Jun-23 | 6012023 | 35341 | 80,755 | Jun-23 | SPIDERMAN2023-06 | Spider Man | SPIDERMAN2752412023-06 |
| SPIDERMAN | 01-May-23 | 5012023 | 35341 | 76,916 | May-23 | SPIDERMAN2023-05 | Spider Man | SPIDERMAN2752412023-05 |
| SPIDERMAN | 01-Apr-23 | 4012023 | 35341 | 72,246 | Apr-23 | SPIDERMAN2023-04 | Spider Man | SPIDERMAN2752412023-04 |
1 Reply
- AnonymousNot applicable
Hi Tobz007 ,
Based on the description, please try the following methods:
1.Create the new measure to calculate monthly distance.
Monthly Distance = VAR CurrentReading = SUM(Table1[Odometer Reading]) VAR PreviousReading = CALCULATE(SUM(Table1[Odometer Reading]), PREVIOUSMONTH(Table1[Date])) RETURN IF(NOT ISBLANK(PreviousReading), CurrentReading - PreviousReading)2.Create the new measure to filter the month.
Total Distance Profile 1 = CALCULATE( SUMX(Table1, [Monthly Distance]), Table2[Profile] = 1 )3.Create the new measure to calculate the percentage.
Percentage Prof 1 = DIVIDE( [Total Distance Profile 1], CALCULATE(SUMX(Table1, [Monthly Distance])))Besides, Is the example data above from Table 1 or Table 2? And, there is no profile column inside the table data. Can you provide the complete table data?
Best Regards,
Wisdom Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.