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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
untapjoseph
Helper I
Helper I

Best approach to creating table visual

I am looking to understand the best approach for creating a table/matrix visual using a quite awkward data set. 

 

The output table needs to look something like this, as a broad guide of the rows and columns i need to show (seperate tables for two types, Alpha and beta):

 

Alpha

 Totalas a % of salesTotal Last Monthas a % of sales
Sales    
Cost    
Overheads    
Refunds    

 

Beta 

 Totalas a % of salesTotal Last Monthas a % of sales
Sales    
Cost    
Overheads    
Refunds    

 

The data set is similar to this example:

 

AreaDateSalesCostOverheadsRefunds
AlphaJan-212111
AlphaFeb-214220
AlphaMar-216331
AlphaApr-218442
AlphaMay-2110551
AlphaJun-2112665
AlphaJul-2114770
AlphaAug-2116881
AlphaSep-2118992
BetaJan-212111
BetaFeb-214220
BetaMar-216331
BetaApr-218442
BetaMay-2110551
BetaJun-2112665
BetaJul-2114770
BetaAug-2116881
BetaSep-2118992

 

Any advice on best practice within power query and/or on the building the table itself would be appreciated. Currently I am working on using calculated groups to filter the different types; the data itself has 35 different types, so would like to reduce the number of measures and speed up process! 

 

Any thoughts are welcome.

Many thanks

1 ACCEPTED SOLUTION

@untapjoseph ,

 

Ok, you need a proper calendar table in your model. This will help enormously with the time intelligence you're trying to use, but also will isolate your date evaluations from context filters on your report.

 

Once you have your calendar table, then you can add a monthNumber column, like this:

//DAX
monthNumber = MONTH(calendarTable[Date])

//M
Date.Month([Date])

 

Then add a relativeMonth column, like this:

//DAX
(YEAR(calendar[Date]) * 12 + calendar[monthNumber])
- (YEAR(TODAY()) * 12 + MONTH(TODAY()))

//M
(Date.Year([Date]) * 12 + [monthNumber])
- (Date.Year(Date.From(DateTime.LocalNow())) * 12 + Date.Month(Date.From(DateTime.LocalNow())))

 

Relate your calendar table to your fact table on calendar[Date] ONE : MANY Data[Reference_Date].

 

You should then be able to write a generic measure, something like this:

 

Sales LQ =
CALCULATE(
  SUM(Data[Sales]) / 1000000,
  calendar[relativeMonth] <= -1
)

 

When you put that measure into your table, just filter the visual on [Area] = "Alpha" etc. and the date evaluation should be insulated from the filtering of your fact table.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
BA_Pete
Super User
Super User

cHi @untapjoseph ,

 

At first glance, your source data appears to be in a fairly efficient format for what you're trying to do, so no Power Query really required here. The only thing you might want to do to incease source efficincy would be to unpivot the [Sales], [Cost], [Overheads] and [Refunds] columns.

 

When you say "35 different types", are you talking about different [Area] values? If so, then you don't need to write specific measures for each [Area]. As your required ouput appears to be segmented by [Area] anyway, you can just write generic measures and apply a visual-level filter by [Area].

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks Pete. yes, there 35 Areas, including alpha and beta. 

 

This is an example of one of the measures, which you can see currently filters the Area within the meaure. Hense, why i am trying to find a better way, to avoid replicating this measure for every area. I was then using the UNION and ROW functions to build the table,  which got me the format i was after but didn't allow me to use a visual-level filter by area...

 

Sales LQ =

VAR Current_Date = MAX(Data[Reference_Date].[Date])
VAR LM_Date = DATE(YEAR(Current_Date),MONTH(Current_Date)-1,DAY(Current_Date))

VAR RESULT = CALCULATE(SUM(Data[Sales])/1000000,
FILTER(Data,Data[Reference_Date]<=LM_Date),
FILTER(Data,Data[Area] = "Alpha"))

RETURN

RESULT
 

I am not looking into using calculation groups as a way to try to build the table using the matrix visual instead, do you think this would work?

 

@untapjoseph ,

 

Ok, you need a proper calendar table in your model. This will help enormously with the time intelligence you're trying to use, but also will isolate your date evaluations from context filters on your report.

 

Once you have your calendar table, then you can add a monthNumber column, like this:

//DAX
monthNumber = MONTH(calendarTable[Date])

//M
Date.Month([Date])

 

Then add a relativeMonth column, like this:

//DAX
(YEAR(calendar[Date]) * 12 + calendar[monthNumber])
- (YEAR(TODAY()) * 12 + MONTH(TODAY()))

//M
(Date.Year([Date]) * 12 + [monthNumber])
- (Date.Year(Date.From(DateTime.LocalNow())) * 12 + Date.Month(Date.From(DateTime.LocalNow())))

 

Relate your calendar table to your fact table on calendar[Date] ONE : MANY Data[Reference_Date].

 

You should then be able to write a generic measure, something like this:

 

Sales LQ =
CALCULATE(
  SUM(Data[Sales]) / 1000000,
  calendar[relativeMonth] <= -1
)

 

When you put that measure into your table, just filter the visual on [Area] = "Alpha" etc. and the date evaluation should be insulated from the filtering of your fact table.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks Pete, this helped alot. Once I had followed your guide, I then used calculated tables to bring through the current total, last month total and %age columns. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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