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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
srk_powerbi
Helper II
Helper II

calculate measure help..

hi ,

i have a table like below. I want to calculate a measure base on current month. Lets say we are in june month now, so I want to calcuate  a measure called '% expected' by using this logic

% cexpected = ( ( sum(Amount) where CalcType = sales ) -  ( sum(Amount) where CalcType = sales expected ))/ ( sum(Amount) where CalcType = sales )

 

for the calculation only consider the months  Jan to May because current month is June.  If we are in next month July, i want this to be calculated for months 'Jan- June' , and so on dynamically. Can anyone suggest please.

 

@v-luwang-msft @Jihwan_Kim  @parry2k @v-deddai1-msft @Greg_Deckler 

 

CustomerProduct   FyFiscalMonthYear    Month              CalcType                                      Amount
Amazonxyz2021202101  Jansales             4000
Amazonxyz2021202102   febsales             1400
Amazonxyz2021202103 Marsales             850
Amazonxyz2021202104 Aprsales           2100
Amazonxyz2021202105Maysales          2300
Amazonxyz2021202106Junsales          4270
Amazonxyz2021202107Julsales2320
Amazonxyz2021202108Augsales3220
Amazonxyz2021202109Sepsales2100
Amazonxyz2021202110Octsales   900
Amazonxyz2021202111Novsales  5300
Amazonxyz2021202112Decsales  7200
Amazonxyz2021202101Jansales expected6500
Amazonxyz2021202102febsales expected200
Amazonxyz2021202103Marsales expected3000
Amazonxyz2021202104Aprsales expected2800
Amazonxyz2021202105Maysales expected1200
Amazonxyz2021202106Junsales expected2500
Amazonxyz2021202107Julsales expected850
Amazonxyz2021202108Augsales expected1500
Amazonxyz2021202109Sepsales expected4000
Amazonxyz2021202110Octsales expected2300
Amazonxyz2021202111Novsales expected8500
Amazonxyz2021202112Decsales expected6500
2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

View solution in original post

v-stephen-msft
Community Support
Community Support

Hi @srk_powerbi ,

 

Based on your sample data, you can create the following measure. My measure is updated dynamically, no slicer selection is required.

 

 

% cexpected = 
var _aa=CALCULATE(SUM('Table'[Amount]),FILTER('Table',[CalcType]="sales"&&[Fy]<=YEAR(TODAY())&&[Fm]<=MONTH(TODAY())))
var _bb=CALCULATE(SUM('Table'[Amount]),FILTER('Table',[CalcType]="sales expected"&&[Fy]<=YEAR(TODAY())&&[Fm]<=MONTH(TODAY())))
return DIVIDE(_aa-_bb,_aa)

 

 

Screenshot 2021-06-21 144628.png

Tips: [Fm] column is a calculated column which retruns the month number.

Best Regards,

Stephen Tao

 

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-stephen-msft
Community Support
Community Support

Hi @srk_powerbi ,

 

Based on your sample data, you can create the following measure. My measure is updated dynamically, no slicer selection is required.

 

 

% cexpected = 
var _aa=CALCULATE(SUM('Table'[Amount]),FILTER('Table',[CalcType]="sales"&&[Fy]<=YEAR(TODAY())&&[Fm]<=MONTH(TODAY())))
var _bb=CALCULATE(SUM('Table'[Amount]),FILTER('Table',[CalcType]="sales expected"&&[Fy]<=YEAR(TODAY())&&[Fm]<=MONTH(TODAY())))
return DIVIDE(_aa-_bb,_aa)

 

 

Screenshot 2021-06-21 144628.png

Tips: [Fm] column is a calculated column which retruns the month number.

Best Regards,

Stephen Tao

 

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

 

parry2k
Super User
Super User

@srk_powerbi although @Ashish_Mathur  solution will work in that case you have to select a period. if your ask is to always calculate % until previous month without selecting a month, add this measure (it is based on the file that @Ashish_Mathur  shared in his response)

 

% Expected until Last Month = 
VAR __date = EOMONTH ( TODAY(), -1 )
RETURN
CALCULATE ( DIVIDE ( [Numerator], [Sales YTD] ), 'Calendar'[Date] <= __date ) 

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

amitchandak
Super User
Super User

@srk_powerbi , In case you have date or can create a date then you can use time intelligence with date table

 

example

calculate([% cexpected], datesmtd('Date'[Date])

 

else create a separate table with year month  (say date) 

add rank column

Month Rank = RANKX(all('Date'),'Date'[year Month],,ASC,Dense)

 

create measures
This Month = CALCULATE([% cexpected], FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank])))
Last Month = CALCULATE([% cexpected], FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank])-1))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

thanks for reply.  here I need to calculate for all the months prior to current month dynamically.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

October NL Carousel

Fabric Community Update - October 2024

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