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
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
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.