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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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))

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

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Kudoed Authors