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
matrix_user
Helper III
Helper III

Display this week's data with last week's data on matrix table.

Hello,

 

I have a matrix table which displays in a column, current seats (OccupiedSeatsTW) available but I also want to include another column dislaying last week's seat availability (OccupiedSeatsLW). When I apply a measure, it does not bring up any results:

 

matrix_user_1-1638061788921.png

1)For OccupiedSeatsTW (this week),  I am using a measure:  OccupiedSeatsTW = DIVIDE([SumOfTakenSeats],[ActiveSeats]).

   For OccupiedSeatsLW (last week) I am using a measure I saw on YouTube:

OccupiedSeatsLW =
VAR CurrentWeek = SELECTEDVALUE ( 'Calendar'[Week Number] )
VAR CurrentYear = SELECTEDVALUE ( 'Calendar'[Year] )
VAR MaxWeekNumber = CALCULATE ( MAX ( 'Calendar'[Week Number] ), ALL ( 'Calendar' ) )
RETURN
SUMX (
FILTER (ALL ('Calendar'),
IF (CurrentWeek = 1,
'Calendar'[Week Number] = MaxWeekNumber && 'Calendar'[Year] = CurrentYear -1,
'Calendar'[Week Number] = CurrentWeek -1 && 'Calendar'[Year] = CurrentYear)),
[ActiveSeats])

 

 The catch is, that my reporting weeks start on Wednesdays and ends on Tuesday;

 

2) My Calendar table (I prefer to write my own tables instead of importing them), and so they consist of the following:

matrix_user_2-1638064421716.png

3) My Source(Fact) table consist of the following and has dates from 03/09/21 tp 16/09/2021:

matrix_user_3-1638064566789.png

4) Measures used to extract results into the matrix for current and last week as follows (a couple of these measures are mentioned in point 1 above:

matrix_user_0-1638065381698.png

 

Is there anyone out there who can help me display OccupiedSeatsLW (for last week) on this matrix?

 

Cheers,

 

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

Hi, 

According to your description, I can roughly understand your requirement, I think you can achieve this using two measures and a calculated column, you can try my steps:

This is the test data I created based on your sample pictures:

vrobertqmsft_0-1638262501977.png

 

Create a calculated column in the main table:

Weeknum = WEEKNUM('Table'[Date],2)

 

Then create two measures like this:

OccupiedSeats LW =

CALCULATE(SUM('Table'[OccupiedSeats]),FILTER(ALL('Table'),[Weeknum]=WEEKNUM(TODAY())-1))
OccupiedSeats TW =

CALCULATE(SUM('Table'[OccupiedSeats]),FILTER(ALL('Table'),[Weeknum]=WEEKNUM(TODAY())))

 

And you can create a table chart to palce the two measures to get what you want, like this:

vrobertqmsft_1-1638262501981.png

 

You can download my test pbix file below

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

6 REPLIES 6
v-robertq-msft
Community Support
Community Support

Hi, 

According to your description, I can roughly understand your requirement, I think you can achieve this using two measures and a calculated column, you can try my steps:

This is the test data I created based on your sample pictures:

vrobertqmsft_0-1638262501977.png

 

Create a calculated column in the main table:

Weeknum = WEEKNUM('Table'[Date],2)

 

Then create two measures like this:

OccupiedSeats LW =

CALCULATE(SUM('Table'[OccupiedSeats]),FILTER(ALL('Table'),[Weeknum]=WEEKNUM(TODAY())-1))
OccupiedSeats TW =

CALCULATE(SUM('Table'[OccupiedSeats]),FILTER(ALL('Table'),[Weeknum]=WEEKNUM(TODAY())))

 

And you can create a table chart to palce the two measures to get what you want, like this:

vrobertqmsft_1-1638262501981.png

 

You can download my test pbix file below

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

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

Thank you Robert. Much appreciated.

Two problems here.

 

First OP is using Tue - Wed weeks, so you want WEEKNUM ( 'Table'[Date], 13 ).

The bigger issue is that your DAX won't work for the first week of a year.

 

If you create a week offset index that doesn't reset across years, then this approach should work fine.

Hi Alexis,

 

Yes I have read a few articles about possible issues when the new year starts. Thank you.

matrix_user
Helper III
Helper III

What I am hoping to get is a matrix that shows last week's period (3/11/2021 to 9/11/2021) in the first column and this week's period (10/11/2021 to 16/11/2021) in the second period.

 

matrix_user_2-1638072119496.png

The end result will also be just the total as below:

 

matrix_user_3-1638072277917.png

 

Can anyone guide me?

AlexisOlson
Super User
Super User

How about something much simpler like this?

OccupiedSeatsLW =
CALCULATE ( [OccupiedSeatsTW], DATEADD ( 'Calendar'[Date], -7, DAY ) )

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.

Top Solution Authors