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
mocha911
Frequent Visitor

Get previous month data (not aggregate/numeric)

Hi folks, 

I am a newbie in power bi and am creating a visual and need to get the "previous month's product" as below -

DateClientNoCurrent ProductPrev Month Product
Tuesday, 31 January 20231A 
Tuesday, 28 February 20231AA
Friday, 31 March 20231AA
Sunday, 30 April 20231AA
Tuesday, 2 May 20231BA
Wednesday, 31 May 20231BA
Friday, 30 June 20231BB
Monday, 31 July 20231BB
Thursday, 31 August 20231BB
Saturday, 30 September 20231BB

 

Do you have any suggestion what I should do?
a bit more info of this dataset - it is a power bi dataset so I can't edit any relationship in the tables. there is a date table, client table and product table. 
I can't add columns into the table either.

So I am thinking to create a measure using "Calculate". This is what I tried - Calculate(max(Product_table[Current Product]), previousmonth(Date_Table[Date]))
this gives me the following result   -

DateClientNoCurrent ProductPrev Month Product
Tuesday, 31 January 20231A 
Tuesday, 28 February 20231AA
Friday, 31 March 20231AA
Sunday, 30 April 20231AA
Friday, 30 June 20231BB
Monday, 31 July 20231BB
Thursday, 31 August 20231BB

 

The month of change (May 2023) is missing in the table which I don't understand why.

Can anyone please help me? thank you

2 ACCEPTED SOLUTIONS
123abc
Community Champion
Community Champion

It looks like you're trying to create a measure in Power BI to show the previous month's product for each client. The issue you're facing might be related to how the relationships between tables are set up in your data model.

Since you mentioned that you can't edit any relationships in the tables, you can try using a combination of CALCULATETABLE and FILTER functions to achieve the desired result. Here's an example measure that you can try:

 

Prev Month Product =
VAR CurrentDate = MAX(Date_Table[Date])
VAR PrevMonth = CALCULATETABLE(ALL(Date_Table), DATEADD(Date_Table[Date], -1, MONTH))
RETURN
CALCULATE(
VALUES(Product_table[Current Product]),
FILTER(
ALL(Client_Table),
Client_Table[ClientNo] = VALUES(Client_Table[ClientNo])
),
FILTER(
PrevMonth,
Date_Table[Date] = CurrentDate
)
)

 

his measure uses a variable to store the current date, then uses CALCULATETABLE to get a table of all dates from the previous month. Finally, it uses CALCULATE with appropriate filters to retrieve the previous month's product for each client.

Please replace Client_Table with the actual name of your client table, and make sure that the column names used in the relationships are correct. Adjust the measure accordingly based on your specific table and column names.

If the issue persists or if you provide more information about your data model, I can further assist you in troubleshooting the problem.

 
 
 

View solution in original post

ThxAlot
Super User
Super User

ThxAlot_0-1702285145094.png

 

For fun only, a showcase of powerful Excel formulas,

ThxAlot_1-1702286249240.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



View solution in original post

3 REPLIES 3
ThxAlot
Super User
Super User

ThxAlot_0-1702285145094.png

 

For fun only, a showcase of powerful Excel formulas,

ThxAlot_1-1702286249240.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



123abc
Community Champion
Community Champion

It looks like you're trying to create a measure in Power BI to show the previous month's product for each client. The issue you're facing might be related to how the relationships between tables are set up in your data model.

Since you mentioned that you can't edit any relationships in the tables, you can try using a combination of CALCULATETABLE and FILTER functions to achieve the desired result. Here's an example measure that you can try:

 

Prev Month Product =
VAR CurrentDate = MAX(Date_Table[Date])
VAR PrevMonth = CALCULATETABLE(ALL(Date_Table), DATEADD(Date_Table[Date], -1, MONTH))
RETURN
CALCULATE(
VALUES(Product_table[Current Product]),
FILTER(
ALL(Client_Table),
Client_Table[ClientNo] = VALUES(Client_Table[ClientNo])
),
FILTER(
PrevMonth,
Date_Table[Date] = CurrentDate
)
)

 

his measure uses a variable to store the current date, then uses CALCULATETABLE to get a table of all dates from the previous month. Finally, it uses CALCULATE with appropriate filters to retrieve the previous month's product for each client.

Please replace Client_Table with the actual name of your client table, and make sure that the column names used in the relationships are correct. Adjust the measure accordingly based on your specific table and column names.

If the issue persists or if you provide more information about your data model, I can further assist you in troubleshooting the problem.

 
 
 

Thank you so much for the solution! it almost works but the final output misses the "May" month which is the month of the change happened. I am guessing because there are two entries (one is not month end) in May which stuffed up the dax. Any solutions for this? As it will always happens on the month of change.

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.