cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## Matrix of measures by different date periods, displayed by category

I am looking to create a chart that shows totals by various date periods, such as Yesterday, Last Month, Month-to-Date (MTD), and Year-to-Date (YTD), etc. I started by making different measures for each of these time periods and putting them in a matrix with the desired category (payment type), but I have yet to figure out how to have the category to display across the columns and the time periods on the rows in a succinct way. Any suggestions would be appreciated!

Desired output:

Desired output

Example of the measure calculations:

``````Yesterday = CALCULATE(SUM(payments[amount])
,FILTER(payments
,payments[pay_date]=TODAY()-1
)
)``````

1 ACCEPTED SOLUTION
Community Support

Hi, @jpshepard

According to your description, you want to "Matrix of measures by different date periods, displayed by category".

Here are the steps you can refer to :
(1)This is my test data:

(2)We need to create a dimension table like this and we do not need to create any relationship between tables.

(3)Then we can create a measure like this:

``````Measure = var _row =  MAX('Rows'[Column1])
var _today =SUMX( FILTER('Table' , 'Table'[pay_date] = TODAY()) , [amount])
var _yesterday = SUMX( FILTER('Table' , 'Table'[pay_date] = TODAY()-1) , [amount])
var _last_month =SUMX( FILTER('Table' , YEAR('Table'[pay_date]) = YEAR(TODAY()) && MONTH('Table'[pay_date]) = MONTH(TODAY())-1) , [amount])
var _MTD =SUMX(  FILTER('Table' ,  YEAR('Table'[pay_date]) = YEAR(TODAY()) && MONTH('Table'[pay_date]) = MONTH(TODAY())  && 'Table'[pay_date]<= TODAY()) ,[amount])
var _YTD =SUMX( FILTER('Table' , YEAR('Table'[pay_date]) = YEAR(TODAY()) && 'Table'[pay_date]<= TODAY()) , [amount])
return
SWITCH(_row,
"Today",_today,
"Yesterday",_yesterday,
"Last Month" , _last_month,
"MTD" , _MTD,
"YTD",_YTD
)``````

(4)Then we can put the fields we need on the matrix visual and we can cort [Column1] by [Column2], the result is as follows:

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

4 REPLIES 4
Community Support

Hi, @jpshepard

According to your description, you want to "Matrix of measures by different date periods, displayed by category".

Here are the steps you can refer to :
(1)This is my test data:

(2)We need to create a dimension table like this and we do not need to create any relationship between tables.

(3)Then we can create a measure like this:

``````Measure = var _row =  MAX('Rows'[Column1])
var _today =SUMX( FILTER('Table' , 'Table'[pay_date] = TODAY()) , [amount])
var _yesterday = SUMX( FILTER('Table' , 'Table'[pay_date] = TODAY()-1) , [amount])
var _last_month =SUMX( FILTER('Table' , YEAR('Table'[pay_date]) = YEAR(TODAY()) && MONTH('Table'[pay_date]) = MONTH(TODAY())-1) , [amount])
var _MTD =SUMX(  FILTER('Table' ,  YEAR('Table'[pay_date]) = YEAR(TODAY()) && MONTH('Table'[pay_date]) = MONTH(TODAY())  && 'Table'[pay_date]<= TODAY()) ,[amount])
var _YTD =SUMX( FILTER('Table' , YEAR('Table'[pay_date]) = YEAR(TODAY()) && 'Table'[pay_date]<= TODAY()) , [amount])
return
SWITCH(_row,
"Today",_today,
"Yesterday",_yesterday,
"Last Month" , _last_month,
"MTD" , _MTD,
"YTD",_YTD
)``````

(4)Then we can put the fields we need on the matrix visual and we can cort [Column1] by [Column2], the result is as follows:

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Frequent Visitor

Aniya, thank you for this wonderful response! It worked perfectly. If you get a chance, do you know how you would also add the # of payments for the time period as well? Like so:

Absolutely no worries if you don't get a chance to look at this. You already helped me so much! Really appreciate it.

Frequent Visitor

Aha I figured it out - I made another measure just like the one you demonstrated, but this time using COUNTX in place of the SUMX. Thank you for showing me the way!

Community Support

Hi, @jpshepard

Glad you solved the problem, we will do our best to answer your questions. If sometimes you forget or omit it for some reason, you can also open a new case and post it to us, we will try our best to help you!

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.