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
Sunkari
Responsive Resident
Responsive Resident

Need help on custom table/matrix format

Hi All,

 

We need to create following using Power BI Table or Matrix. Rows contain different metrics and columns are different time periods. Could you please provide inputs in getting follow structure.

 

PeriodThree Months BackTwo Months BackPrevious MonthCurrent MonthYTD
Metric     
Metrc1100150200120570
Metrc2200100250220770
Metrc33002003003001100
1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Sunkari,

 

I'd like to suggest you create four measures to calculate these result, then drag them to matrix with Period as Rows field, date as Columns field.

 

Perv Month = 
var temp=LASTNONBLANK(Smaple[Type],[Type])
var calculateDate=DATE(MAX([Date].[Year]),MAX([Date].[MonthNo])-1,MAX([Date].[Day]))
Return
SUMX(FILTER(ALL(Smaple),[Type]=temp&&FORMAT([Date],"yyyy mmm")=FORMAT(calculateDate,"yyyy mmm")),[Amount])

Perv 2 Month = 
var temp=LASTNONBLANK(Smaple[Type],[Type])
var calculateDate=DATE(MAX([Date].[Year]),MAX([Date].[MonthNo])-2,MAX([Date].[Day]))
Return
SUMX(FILTER(ALL(Smaple),[Type]=temp&&[Date].[MonthNo]=MONTH(calculateDate)&&[Date].[Year]=YEAR(calculateDate)),[Amount])

Perv 3 Months = 
var temp=LASTNONBLANK(Smaple[Type],[Type])
var calculateDate=DATE(MAX([Date].[Year]),MAX([Date].[MonthNo])-3,MAX([Date].[Day]))
Return
SUMX(FILTER(ALL(Smaple),[Type]=temp&&[Date].[MonthNo]=MONTH(calculateDate)&&[Date].[Year]=YEAR(calculateDate)),[Amount])

YTD = 
var temp=LASTNONBLANK(Smaple[Type],[Type])
var calculateDate=DATE(MAX([Date].[Year]),1,1)
Return
SUMX(FILTER(ALL(Smaple),[Type]=temp&&[Date]>=calculateDate&&[Date]<=MAX(Smaple[Date])),[Amount])

 

 

Capture.PNG

 

BTW, current table/matrix not support auto summary the previous value.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @Sunkari,

 

I'd like to suggest you create four measures to calculate these result, then drag them to matrix with Period as Rows field, date as Columns field.

 

Perv Month = 
var temp=LASTNONBLANK(Smaple[Type],[Type])
var calculateDate=DATE(MAX([Date].[Year]),MAX([Date].[MonthNo])-1,MAX([Date].[Day]))
Return
SUMX(FILTER(ALL(Smaple),[Type]=temp&&FORMAT([Date],"yyyy mmm")=FORMAT(calculateDate,"yyyy mmm")),[Amount])

Perv 2 Month = 
var temp=LASTNONBLANK(Smaple[Type],[Type])
var calculateDate=DATE(MAX([Date].[Year]),MAX([Date].[MonthNo])-2,MAX([Date].[Day]))
Return
SUMX(FILTER(ALL(Smaple),[Type]=temp&&[Date].[MonthNo]=MONTH(calculateDate)&&[Date].[Year]=YEAR(calculateDate)),[Amount])

Perv 3 Months = 
var temp=LASTNONBLANK(Smaple[Type],[Type])
var calculateDate=DATE(MAX([Date].[Year]),MAX([Date].[MonthNo])-3,MAX([Date].[Day]))
Return
SUMX(FILTER(ALL(Smaple),[Type]=temp&&[Date].[MonthNo]=MONTH(calculateDate)&&[Date].[Year]=YEAR(calculateDate)),[Amount])

YTD = 
var temp=LASTNONBLANK(Smaple[Type],[Type])
var calculateDate=DATE(MAX([Date].[Year]),1,1)
Return
SUMX(FILTER(ALL(Smaple),[Type]=temp&&[Date]>=calculateDate&&[Date]<=MAX(Smaple[Date])),[Amount])

 

 

Capture.PNG

 

BTW, current table/matrix not support auto summary the previous value.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thanks bro.I will try this and let you know.

Sunkari
Responsive Resident
Responsive Resident

@Phil_Seamark: Any inputs

Sunkari
Responsive Resident
Responsive Resident

@v-ljerr-msft:Any inputs

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.