Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jpshepard
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 outputDesired output

 

Example of the measure calculations:

 

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

 

 

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
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:

vyueyunzhmsft_0-1684978450839.png

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

vyueyunzhmsft_1-1684978478541.png

(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:

vyueyunzhmsft_2-1684978548656.png

 

 

 

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

View solution in original post

4 REPLIES 4
v-yueyunzh-msft
Community Support
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:

vyueyunzhmsft_0-1684978450839.png

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

vyueyunzhmsft_1-1684978478541.png

(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:

vyueyunzhmsft_2-1684978548656.png

 

 

 

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

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:

Screenshot 2023-06-08 at 1.54.12 PM.png

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

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!

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.