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

PREVIOUSMONTH in DIRECTQUERY, for DIFFERENT Products

Based on the next example of Data:

PRODUCTDATE_XSALES
AAAA1/1/20181000
AAAA2/1/20181100
AAAA3/1/20181200
AAAA4/1/20181300
BBBB1/1/20181400
BBBB2/1/20181500
BBBB3/1/20181600
BBBB4/1/20181700
CCCC1/1/20181800
CCCC2/1/20181900
CCCC3/1/20182000
CCCC4/1/20182100

 

I am trying to get the data from previous month, per Product, So I used the Following formulas:

    Sales All=SUM('data'[SALES])     *created a Meausre

    Sales PM=CALCULATE([Sales ALL], PREVIOUSMONTH(Date)   *created a Meausre

 

Thus, hoping to obtain the following table

PRODUCTDATE_XSALESSALES PM
AAAA1/1/20181000 
AAAA2/1/201811001000
AAAA3/1/201812001100
AAAA4/1/201813001200
BBBB1/1/20181400 
BBBB2/1/201815001400
BBBB3/1/201816001500
BBBB4/1/201817001600
CCCC1/1/20181800 
CCCC2/1/201819001800
CCCC3/1/201820001900
CCCC4/1/201821002000

 

However, It is not filtering per Product, so it is basically Suming the Sales for ALL Products, SO I am having this result:

PRODUCTDATE_XSALESSALES PM
AAAA1/1/20181000 
AAAA2/1/201811004200
AAAA3/1/201812004500
AAAA4/1/201813004800
BBBB1/1/20181400 
BBBB2/1/201815004200
BBBB3/1/201816004500
BBBB4/1/201817004800
CCCC1/1/20181800 
CCCC2/1/201819004200
CCCC3/1/201820004500
CCCC4/1/201821004800

 

So for 2/1/2018, is adding up all 1/1/2018 Sales data, regardless of the product (1000+1400+1800)

I need for AAAA for 2/1/2018 the value of 1000, and so on....

What am I missing? Can you guide me?

6 REPLIES 6
Hardik
Continued Contributor
Continued Contributor

I think you need to calculate the sales on a column basis.You can sort the table data ccording to date and calculate if the month of the date is less than the month of the other date the sales should be of the previous month and so on

The Sales is a straight data. I indicated Sales as an example, but could be other value, such as age, or weight. My problem is that this is accumulating the value, not considering the different products.

In this Example, If a SITE is not selected, the previous month amount (COGS) is OK,

It is Showing the amount of february in March, and so on.....

example1.JPG

However, when I select one SITE, the Previous month Column does not change to the selected Site, it remains the overall amount:

example2.JPG

The Formulas I used are:

ALL COGS= CALCULATE ( SUM ( Data[COGS] ) )

COGS PM = calculate ( [ALL COGS] , PREVIOUSMONTH ( Table_Dates[Date] ) )

 

Should I used a Filter? how? Please guide me. Thanks!

Hi,

 

From which Table have you built the Site slicer?


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

HI @jvalencia,


Current power bi not support to use slicer or filter to create dynamic calculated column/table, please use measure to instead calculate column.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hello, they are Measures, not Calculated Columns.

The filter I was using it, in order to select another category and then I could have the PM to analize.

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.