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
funklordofusa
Helper I
Helper I

Sum IF conditional on date

Hi experts!  

 

I am having trouble writing a measure to give me sum of sales for months that have passed and a run rate for the current month.

 

The description of what I'm trying to accomplish is:

If month is previous to this month, sum of sales, if month is this month, run rate.  Is there a conventional way to accomplish this?

 

Thanks for your help everyone!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

With the month name alone we cannot determine if the month is the current month or not because the same month comes every year. So I took the liberty to change your table structure and put the actuals dates in your date field as shown below...

 

Table  Name: RawData

 

Datevalue
01-01-20192
02-01-20194
03-01-20193
04-01-20192
01-02-20193
02-02-20191
03-02-20194
04-02-20194
01-03-20193
02-03-20192
03-03-20194
04-03-20193
01-04-20194
02-04-20192
29-06-20195

 

Now to get the desired results you have to add one calculated column before writing your measure.

 

Calculated Column : MonthName

MonthName = FORMAT(RawData[Date],"mmm")

Measure

SUM** = IF(
MAX(RawData[Date])< DATE(YEAR(TODAY()),MONTH(TODAY()),1),
SUMX(RawData,RawData[value]),
12)

This will give you the result. Please note that I have written 12 in the measure. You may change that to the formula for calculating the run rate as per your requirement.

 

View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @funklordofusa,

 

This is very low information to help you can you share some sample data and how your model is set up and expected results.

 

Please see this post regarding How to Get Your Question Answered Quickly:

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490 (courtesy of @Greg_Deckler).

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Sure.  First table is the raw data, second is just the sum of raw data and third is the output I'm hoping to show--sum for the 3 completed months but the runrate (separate measure) for April.

datevalue DateSum DateSum** 
Jan2 Jan11 Jan11 
Jan4 Feb12 Feb12 
Jan3 Mar12 Mar12 
Jan2 Apr6 Apr12 
Feb3       
Feb1       
Feb4       
Feb4       
Mar3       
Mar2       
Mar4       
Mar3       
Apr4       
Apr2       
Anonymous
Not applicable

With the month name alone we cannot determine if the month is the current month or not because the same month comes every year. So I took the liberty to change your table structure and put the actuals dates in your date field as shown below...

 

Table  Name: RawData

 

Datevalue
01-01-20192
02-01-20194
03-01-20193
04-01-20192
01-02-20193
02-02-20191
03-02-20194
04-02-20194
01-03-20193
02-03-20192
03-03-20194
04-03-20193
01-04-20194
02-04-20192
29-06-20195

 

Now to get the desired results you have to add one calculated column before writing your measure.

 

Calculated Column : MonthName

MonthName = FORMAT(RawData[Date],"mmm")

Measure

SUM** = IF(
MAX(RawData[Date])< DATE(YEAR(TODAY()),MONTH(TODAY()),1),
SUMX(RawData,RawData[value]),
12)

This will give you the result. Please note that I have written 12 in the measure. You may change that to the formula for calculating the run rate as per your requirement.

 

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.