March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Matrix Table Output:
Example output demonstrated in excel with pic of slicers being used:
In my measures I use a logic condition to check if any months in the most current year are missing.
Problem
Pic below is for demonstration purposes.
Desired Outcome
Select ALL in the dashboard slicer,
Actual dashboard table matrix pic below with text above totals that are not correct:
PBI File
https://myaccount.dropsend.com/file/2f593847fa068f03
If link expires, msg me to add new download link.
Your time is greatly valued.
Thx!
Solved! Go to Solution.
You can try the following. Based on the little bit of testing I did they seem to work.
Create a measure that determines the maximum month number from the report dates...
maxMonthNumber =
MONTH(
CALCULATE(
MAX('F-Cargo'[report_date]),
ALLEXCEPT(_Calendar, _Calendar[Year])
)
)
Then change the following measures...
Cargo MT LM =
SUMX(
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
CALCULATE(
IF(
ISBLANK([Cargo MT]),
BLANK(),
CALCULATE([Cargo MT], PREVIOUSMONTH(_Calendar[Date]))
)
)
)
Cargo MT LY =
SUMX(
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
CALCULATE(
IF(
ISBLANK( [Cargo MT] ),
BLANK(),
CALCULATE([Cargo MT], SAMEPERIODLASTYEAR((_Calendar[Date])))
)
)
)
Cargo MT YTD -2 Yr =
var _vTable =
SUMMARIZE(
_Calendar,
_Calendar[Month],
"__MT2Yr", IF(
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATEADD('_Calendar'[Date], -2, YEAR))
)
)
Return
MAXX(_vTable,[__MT2Yr])
Cargo MT 2019 =
var _vTable =
SUMMARIZE(
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
_Calendar[Year],
_Calendar[Month],
"__MT2019", IF(
ISBLANK([Cargo MT]),
BLANK(),
CALCULATE([Cargo MT], DATESINPERIOD(_Calendar[Date], DATE(2019,MONTH(MIN(_Calendar[Date])),01), 1, MONTH))
)
)
Return
SUMX(_vTable,[__MT2019])
Cargo MT YTD LY =
var _vTable =
SUMMARIZE(
_Calendar,
_Calendar[Month],
"__MTLY", IF(
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATEADD('_Calendar'[Date], -1, YEAR))
)
)
Return
MAXX(_vTable,[__MTLY])
Cargo MT YTD 2019 =
var _vTable =
SUMMARIZE(
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
_Calendar[Year],
_Calendar[Month],
"__MT2019YTD", IF(
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATESINPERIOD(_Calendar[Date], DATE(2019,MONTH(MIN(_Calendar[Date])),01), 1, MONTH))
)
)
Return
MAXX(_vTable,[__MT2019YTD])
Hope this gets you pointed in the right direction.
Proud to be a Super User! | |
You can try the following. Based on the little bit of testing I did they seem to work.
Create a measure that determines the maximum month number from the report dates...
maxMonthNumber =
MONTH(
CALCULATE(
MAX('F-Cargo'[report_date]),
ALLEXCEPT(_Calendar, _Calendar[Year])
)
)
Then change the following measures...
Cargo MT LM =
SUMX(
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
CALCULATE(
IF(
ISBLANK([Cargo MT]),
BLANK(),
CALCULATE([Cargo MT], PREVIOUSMONTH(_Calendar[Date]))
)
)
)
Cargo MT LY =
SUMX(
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
CALCULATE(
IF(
ISBLANK( [Cargo MT] ),
BLANK(),
CALCULATE([Cargo MT], SAMEPERIODLASTYEAR((_Calendar[Date])))
)
)
)
Cargo MT YTD -2 Yr =
var _vTable =
SUMMARIZE(
_Calendar,
_Calendar[Month],
"__MT2Yr", IF(
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATEADD('_Calendar'[Date], -2, YEAR))
)
)
Return
MAXX(_vTable,[__MT2Yr])
Cargo MT 2019 =
var _vTable =
SUMMARIZE(
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
_Calendar[Year],
_Calendar[Month],
"__MT2019", IF(
ISBLANK([Cargo MT]),
BLANK(),
CALCULATE([Cargo MT], DATESINPERIOD(_Calendar[Date], DATE(2019,MONTH(MIN(_Calendar[Date])),01), 1, MONTH))
)
)
Return
SUMX(_vTable,[__MT2019])
Cargo MT YTD LY =
var _vTable =
SUMMARIZE(
_Calendar,
_Calendar[Month],
"__MTLY", IF(
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATEADD('_Calendar'[Date], -1, YEAR))
)
)
Return
MAXX(_vTable,[__MTLY])
Cargo MT YTD 2019 =
var _vTable =
SUMMARIZE(
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
_Calendar[Year],
_Calendar[Month],
"__MT2019YTD", IF(
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATESINPERIOD(_Calendar[Date], DATE(2019,MONTH(MIN(_Calendar[Date])),01), 1, MONTH))
)
)
Return
MAXX(_vTable,[__MT2019YTD])
Hope this gets you pointed in the right direction.
Proud to be a Super User! | |
Wow jgeddes,
Your amazing.
I hacked and chopped away at this for weeks.
I was moving in the right direction conceptually but I don't have the depth of knowledge that you have.
I will reverse engineer your work in the hopes of gaining some knowledge.
I am forever greatful to you for your help.
I also want to thank Ashish_Mathur on my initial problem. He was helpful and was leading me in the right direction.
jgeddes, your a godsend.
Forever greatful,
DAXRichard
Thanks for the kind words.
Here are the basic ideas around how this works
maxMonthNumber =
MONTH(//gets month number
CALCULATE(
MAX('F-Cargo'[report_date]), //calculates the maximum date
ALLEXCEPT(_Calendar, _Calendar[Year]) //looks for all dates in the _Calendar table allowing the [Year] to be filtered or have a contextual filter applied e.g row in a matrix
)
)
Cargo MT LM =
SUMX(//iterates over the virtual table of month numbers, summing the Cargo MT value from the previous month
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]), //creates a virtual table of month numbers that are less than or equal to the maxMonthNumber
CALCULATE(//returns the Cargo MT value from the previous month as long as it is not blank
IF(
ISBLANK([Cargo MT]),
BLANK(),
CALCULATE([Cargo MT], PREVIOUSMONTH(_Calendar[Date]))
)
)
)
Cargo MT YTD -2 Yr =
var _vTable = //variable used to create the virtual table
SUMMARIZE(//summarize the _Calendar table by month names
_Calendar,
_Calendar[Month],
"__MT2Yr", IF( //creates a column in the summarized table that displays the Cargo MT YTD value from 2 years ago as long as it is not blank
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATEADD('_Calendar'[Date], -2, YEAR))
)
)
Return
MAXX(_vTable,[__MT2Yr]) //return the largest value in the YTD virtual table i.e. the last value
Cargo MT 2019 =
var _vTable =
SUMMARIZE(//summarize the _Calendar table by Year and Month name for month numbers less or equal to the maxMonthNumber
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
_Calendar[Year],
_Calendar[Month],
"__MT2019", IF(
ISBLANK([Cargo MT]),//if the Cargo MT value is blank, blank is returned else the monthly value from 2019 is returned
BLANK(),
CALCULATE([Cargo MT], DATESINPERIOD(_Calendar[Date], DATE(2019,MONTH(MIN(_Calendar[Date])),01), 1, MONTH)) // calculates the Cargo MT for each month in 2019 for each row in the virtual table
)
)
Return
SUMX(_vTable,[__MT2019])// sums the values in the virtual table
Cargo MT YTD LY =
var _vTable =
SUMMARIZE(//create a virtual table that summarizes the _Calendar table by month name
_Calendar,
_Calendar[Month],
"__MTLY", IF(//add a column in the virtual table that displays the Cargo MT value for the year that is one less than the current year context
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATEADD('_Calendar'[Date], -1, YEAR))
)
)
Return
MAXX(_vTable,[__MTLY])//returns the largest value in the virtual table (last month's value)
Cargo MT YTD 2019 =
var _vTable =
SUMMARIZE(//create a virtual table that summarizes the _Calendar table by Year and Month Name for any month numbers that are less than or equal to the maxMonthNumber
FILTER(_Calendar, _Calendar[MonthNu] <= [maxMonthNumber]),
_Calendar[Year],
_Calendar[Month],
"__MT2019YTD", IF(//adds a column that displays the Cargo MT value for months where Cargo MT is not blank
ISBLANK([Cargo MT]),
BLANK(),
TOTALYTD([Cargo MT], DATESINPERIOD(_Calendar[Date], DATE(2019,MONTH(MIN(_Calendar[Date])),01), 1, MONTH))//calculates YTD value of Cargo MT for each month in 2019
)
)
Return
MAXX(_vTable,[__MT2019YTD])//returns the largest value in the virtual table, ie the last month's value
Cheers
Proud to be a Super User! | |
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
85 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |