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
clopez
Regular Visitor

Help with a Meassure

Hi friends, Im new in this community, and im working with power Bi around 6 months, and its great!!

 

Im trying to make a meassure in power Bi desktop, i got a database of daily stocks and different kind of inventory status (like scrap or expired stock). I have records of the stock by the end of each month, and i have to do a formula to calculate de difference of the stock in one month minus the stock of the previous month, to make a KPI of the gap of the scraps in each month. (comparing the stock of one month - the stock of the previous month) and be able to graph it.

i Cant do it in the meassure, can you please help me how to do it?

 

Thank you so much, i dont speak english so far :P, i hope you can understand it.

 

1 ACCEPTED SOLUTION
v-huizhn-msft
Employee
Employee

Hi @clopez,

First, please create a calendar table using formula. I assume table name stored stock records is 'Stock'.

Calendar=CALENDAR(MIN(Stock[date]), TODAY())


Then create a relationship between 'Stock' table and Calendar table by date field. More details, please review: Create and manage relationships in Power BI Desktop. Create a calculated column to get month using formula: Month=Month(Calendar[Date])

Finally, create a measure using the formula. And create a table visual, select the month and measure as value, you will get the difference in each month.

difference =
COUNT ( Stock[record] )
    - CALCULATE ( COUNT ( Stock[record] ), PREVIOUSMONTH ( Calendar[Date] ) )

Please know how the PREVIOUSMONTH work from here: https://msdn.microsoft.com/en-us/library/ee634758?ui=en-US&rs=en-US&ad=US.

And there are similar threads for your references.

Calculate difference from previous month

Comparison- current month vs previous month 

Best Regards,
Angelia

 

View solution in original post

2 REPLIES 2
v-huizhn-msft
Employee
Employee

Hi @clopez,

Have you resolved your issue? If you have, welcome to share your solution or mark the right reply as answer. More people will benefit from here.

Best Regards,
Angelia

v-huizhn-msft
Employee
Employee

Hi @clopez,

First, please create a calendar table using formula. I assume table name stored stock records is 'Stock'.

Calendar=CALENDAR(MIN(Stock[date]), TODAY())


Then create a relationship between 'Stock' table and Calendar table by date field. More details, please review: Create and manage relationships in Power BI Desktop. Create a calculated column to get month using formula: Month=Month(Calendar[Date])

Finally, create a measure using the formula. And create a table visual, select the month and measure as value, you will get the difference in each month.

difference =
COUNT ( Stock[record] )
    - CALCULATE ( COUNT ( Stock[record] ), PREVIOUSMONTH ( Calendar[Date] ) )

Please know how the PREVIOUSMONTH work from here: https://msdn.microsoft.com/en-us/library/ee634758?ui=en-US&rs=en-US&ad=US.

And there are similar threads for your references.

Calculate difference from previous month

Comparison- current month vs previous month 

Best Regards,
Angelia

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.