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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
PBIUWO
Helper III
Helper III

How to create dynamic data table to create customized matrix & populating its value?

I have a Sales Data Table that has columns Item Code, Item Description, Sale Month, and Sale Quantity.

Item CodeItem DescriptionSales MonthSales Quantity

123-ABC

SampDecember, 20205
123-ABCSampMarch, 20206
123-ABCSampNovember, 20202
144-AAASample TNovember, 20203
333-RRRSample TeOctober, 20204

 

I wanted to create a table/matrix visual, that has Item Code, Sales Months (January, February, March etc) with the Sales Quantity as the value and Summarized Sales.

Item CodeItem DescriptionJanuary 2020February 2020March 2020April 2020May 2020June 2020July 2020August 2020September 2020October 2020November 2020December 2020Summarized Sales
123-ABCSamp00600000002513

 

So I have created a customized data table to use as a reference. 

Customized ColumnReference
Item Code1
Item Description2
January 20203
.. 
... 
... 
December 202014
Summarized Sales15

 

How do I make the value of the months dynamic? so it changes the value to 12 months referenced to todays date? 

In the value of the Matrix, How do I make the Matrix values reference the new dynamic months?

 

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

Hi @PBIUWO ,

 

First create a date table as below:

calendar table = 
var _year=IF(MONTH(TODAY())<12,YEAR(TODAY())-1,YEAR(TODAY()))
var _month=IF(MONTH(TODAY())<12,MONTH(TODAY())+1,1)
Return
CALENDAR(DATE(_year,_month,1),TODAY())

Then create a column in the calendar table:

Month year = FORMAT('calendar table'[Date],"MMMM")&" "&YEAR('calendar table'[Date])

And a measure as below:

Measure = 
var _tab=SUMMARIZE('Table','Table'[Item Code],'calendar table'[Month year],"sumofsales",SUM('Table'[Sales Quantity]))
return 
SUMX(_tab,[sumofsales])+0

 Finally,you will see:

v-kelly-msft_0-1611651162152.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

7 REPLIES 7
v-kelly-msft
Community Support
Community Support

Hi @PBIUWO ,

 

First create a date table as below:

calendar table = 
var _year=IF(MONTH(TODAY())<12,YEAR(TODAY())-1,YEAR(TODAY()))
var _month=IF(MONTH(TODAY())<12,MONTH(TODAY())+1,1)
Return
CALENDAR(DATE(_year,_month,1),TODAY())

Then create a column in the calendar table:

Month year = FORMAT('calendar table'[Date],"MMMM")&" "&YEAR('calendar table'[Date])

And a measure as below:

Measure = 
var _tab=SUMMARIZE('Table','Table'[Item Code],'calendar table'[Month year],"sumofsales",SUM('Table'[Sales Quantity]))
return 
SUMX(_tab,[sumofsales])+0

 Finally,you will see:

v-kelly-msft_0-1611651162152.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

Ashish_Mathur
Super User
Super User

Hi,

A matrix visual will work just fine.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
smpa01
Super User
Super User

@PBIUWOcan you try this - https://drive.google.com/file/d/1VeeUWzJIOmqaAlb9p7fgn0DnOGFABQED/view?usp=sharing

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I don't have access to this 

Geradav
Responsive Resident
Responsive Resident

@PBIUWO 

Not so sure to understand what you are trying to achieve with your dynamic table, but in Power BI ther is a visual call Matrix that works like a Pivot Table in Excel and that would give you the possibility to achieve exactly what you want with "table/matrix" you mention.

 

David

@Geradav 

 

Yes, I am currently using a Matrix visual. But for each "value" being added onto the visual, it will create 2 columns. That's the flaw with the matrix. 

 

So for example, if I add Item Description from the data table, it will create Item Description for each column beside the Sales Quantity in the Matrix. 

 

Frank
Frequent Visitor

As I understand it, you want Rolling 12 Months sales data.  Below is a way to accomplish that.

 

https://community.powerbi.com/t5/Desktop/Trailing-12-or-Rolling-12-month-sum/m-p/164419

 

In instances where my data has periods and not actual dates, I will make a calendar table and sequence them, i.e Jan 2020 = 1, Feb 2020 = 2, .....Jan 2021 = 13 and so on. Filter on current date and it should do waht you are asking.

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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