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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

How to repeat last values of a column till the end of the matrix?

Hi All,

 

I have a matrix where I need to repeat the last values of the column till the end of the matrix.

 

For example:

 

I have a visual table like the below matrix in my power bi 

 

Report DateJun-21Jul-21Aug-21Sep-21Oct-21Nov-21Dec-21
Jun-2110020010040070010001300
Jul-2150450200100100100100
Aug-21 100350200200200200
Sep-21  100200200200200
Oct-21   500100100100
Nov-21    200300400
Dec-21     100450

 

I want my visual to look like the below table (i.e; the bold values should repeat till Dec-21)

 

Report DateJun-21Jul-21Aug-21Sep-21Oct-21Nov-21Dec-21
Jun-2110020010040070010001300
Jul-2150450200100100100100
Aug-2150100350200200200200
Sep-2150100100200200200200
Oct-2150100100500100100100
Nov-2150100100500200300400
Dec-2150100100500200100450

 


It will be a great help if someone could advise how to write a dax?

Thanks in advance



1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

From your screenshot I know that there are two date columns in matrix row and column.

I suggest you to create two unrelated date table based on two date columns in your data table.

Then try this code. Report Date and Date2 table are dax table based on date columns in my data table.

Fill Last Value in Matrix = 
VAR _T1 = GENERATE(VALUES('Table'[Report Date]),VALUES('Table'[Date2]))
VAR _T2 = ADDCOLUMNS(_T1,"Value",CALCULATE(SUM('Table'[Value]),FILTER('Table',AND('Table'[Report Date] = EARLIER([Report Date]),'Table'[Date2]=EARLIER([Date2])))))
VAR _T3 = ADDCOLUMNS(_T2,"MaxDate",MAXX(FILTER(_T2,AND([Date2]=EARLIER([Date2]),[Value]<>BLANK())),[Report Date]))
VAR _T4 = ADDCOLUMNS(_T3,"NewValue",IF([Value] <>BLANK(),[Value],SUMX(FILTER(_T3,AND([Date2]=EARLIER([Date2]),[Report Date]=[MaxDate])),[Value])))
RETURN
SUMX(FILTER(_T4,AND([Report Date] = MAX('Report Date'[Report Date]),[Date2]=MAX(Date2[Date2]))),[NewValue])

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

From your screenshot I know that there are two date columns in matrix row and column.

I suggest you to create two unrelated date table based on two date columns in your data table.

Then try this code. Report Date and Date2 table are dax table based on date columns in my data table.

Fill Last Value in Matrix = 
VAR _T1 = GENERATE(VALUES('Table'[Report Date]),VALUES('Table'[Date2]))
VAR _T2 = ADDCOLUMNS(_T1,"Value",CALCULATE(SUM('Table'[Value]),FILTER('Table',AND('Table'[Report Date] = EARLIER([Report Date]),'Table'[Date2]=EARLIER([Date2])))))
VAR _T3 = ADDCOLUMNS(_T2,"MaxDate",MAXX(FILTER(_T2,AND([Date2]=EARLIER([Date2]),[Value]<>BLANK())),[Report Date]))
VAR _T4 = ADDCOLUMNS(_T3,"NewValue",IF([Value] <>BLANK(),[Value],SUMX(FILTER(_T3,AND([Date2]=EARLIER([Date2]),[Report Date]=[MaxDate])),[Value])))
RETURN
SUMX(FILTER(_T4,AND([Report Date] = MAX('Report Date'[Report Date]),[Date2]=MAX(Date2[Date2]))),[NewValue])

Result is as below.

1.png

Best Regards,
Rico Zhou

 

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

Anonymous
Not applicable

Hi Rico,

 

Sorry for the late reply

And Thank you so much.
It helped me to create the table how I wanted.

Thanks

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.