cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Rck7 Helper II
Helper II

How to calculate conditional running totals in Power BI?

Hi Friends,

I have a date column with dates starting from 27-OCT-2014 to current. I have created a column chart which displays the data on contract year basis.

For example:

Contract year 1 has dates from 27-OCT-2014 to 26-oct-2017.

contract year 2 has dates from 27-oct-2017 to 26-oct-2020 and follows the same for the years to come.

I have created a running total measure which is currently giving me the total of the entire table including the contract year 2. Instead, I would like to create a measure which calculates the running total starting from 27-oct-2017 and upcoming months(as I have entered the year 2 not including year 1).

Additionally, I would aslo like to create a measure to calculate projected running totals for the contract year 2 (i.e. 62000/month).
Here are my measures:
Running totals: 
Contract year2 Totals =
CALCULATE (
FILTER (
ALL (TokenRecords[UsageDate]),
TokenRecords[UsageDate] >= DATE (10,27,2017 )
&& TokenRecords[UsageDate] <= MAX (TokenRecords[UsageDate])
)
)

Projected totals:
Projected Totals =
COUNTROWS (
SUMMARIZE ( TokenRecords, TokenRecords[FiscalYear], TokenRecords[FiscalMonth]))*62891


Any help would be very much appreciated. 
Thank you.


1 ACCEPTED SOLUTION

Accepted Solutions
Super User IV
Super User IV

Re: How to calculate conditional running totals in Power BI?

Hi @Rck7,

 

Try this

 

=CALCULATE(SUM(Tokenrecords[amount]),DATESBETWEEN(Calendar[Date],DATE(2017,10,1),TODAY()))

 

I have assumed that you have a table named calendar with running dates.  There is a relationship from the Date column of the TokenRecords table to the Date column of the Calendar table.

 

Hope this helps.


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

View solution in original post

10 REPLIES 10
WolfBiber Responsive Resident
Responsive Resident

Re: How to calculate conditional running totals in Power BI?

Hey,

sorry, but I dont understand what you want 🙂

Greetings.

Super User IV
Super User IV

Re: How to calculate conditional running totals in Power BI?

Hi @Rck7,

 

Here are a few fallacies:

 

  1. The DATE function take inputs as Y,M,D.  Check your inputs
  2. The first inout of the CALCULATE() function is a measure.  I do not see that in your formula

Explain the business problem, paste some data and show the expected result.


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

Re: How to calculate conditional running totals in Power BI?

@Ashish_Mathur Hi.  I am trying to build a dashboard showing data on a contract year basis. i.e. (CY1 is from 27/OCT/2014- 26/OCT/2017) which just ended. Now, I have started adding data for CY2 starting (27/OCT/2017- 26/OCT/2020) & follows the same for the years to come. 

I have created a single datatable for my dashboard with a usage date column & a value column where I update on a biweekly basis.  

Issue:
I created a card on my dashboard which shows the running totals of current contract year for the chart displayed on my dashboard. The problem is that currently my card is displaying the running total value of all the dates available in the usagedate column(i.e. Contract Year 1 + Contract year 2). Instead, I want the card to display the running total starting from 27/OCT/2017. 

Please suggest me a measure where I could display the running totals just for CY2 as it is the current year data that i am displaying in my dashboard.

Here is what i am getting: 
My measure is adding up all the CY1 & CY2 data from my usage date table(i.e. CY1: 1882898 + CY2: 76570) 

12-10-2017 5-56-55 PM.png
Istead the Value should be 76570(starting 27/OCT/2017) as of today. 
Kindly help!!!
Thank you.
  

Rck7 Helper II
Helper II

Re: How to calculate conditional running totals in Power BI?

@WolfBiber. Please, see my comment to the post. Thanks!!!

Super User IV
Super User IV

Re: How to calculate conditional running totals in Power BI?

Hi @Rck7,

 

Try this

 

=CALCULATE(SUM(Tokenrecords[amount]),DATESBETWEEN(Calendar[Date],DATE(2017,10,1),TODAY()))

 

I have assumed that you have a table named calendar with running dates.  There is a relationship from the Date column of the TokenRecords table to the Date column of the Calendar table.

 

Hope this helps.


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

View solution in original post

purana2002 Helper I
Helper I

Re: How to calculate conditional running totals in Power BI?

I have Table like 

 

Date , Dayof week (Sunday, Monday etc), Region(East, West, Central), CallCount

 

I want to calulate MTD AVG_CallCount by Dayof the week For that region & YTD AVG_CallCount by Dayof the week For that region

 

 

 Example , MTD monday Avg for 2/11

 

02/11/2018 is the 2nd monday of Feb and 7th Monday of the year.

 

Now I want to calculate AVG call count for all the Monday till 2/11/2018 (including 2/11) for February , 2/5 & 2/11, for MTD 

 

&  AVG call count for all the Monday till 2/11/2018 (including 2/11) for 2018 , for YTD.

 

DateWeekofDayRegionCallCountAvg_MTD_Weekoftheday
1/1/2018MondayCentral100100
1/1/2018MondayEast200 200
1/1/2018MondayWest300 300
1/2/2018TuesdayCentral150 150
1/2/2018TuesdayEast250 250
1/2/2018TuesdayWest350 350
1/3/2018WednesdayCentral  
1/3/2018WednesdayEast  
1/3/2018WednesdayWest  
1/4/2018ThursdayCentral  
1/4/2018ThrusdayEast  
1/4/2018ThrusdayWest  
1/5/2018FridayCentral  
1/5/2018FridayEast  
1/5/2018FridayWest  
1/6/2018SaturdayCentral  
1/6/2018SaturdayEast  
1/6/2018SaturdayWest  
1/7/2018SundayCentral  
1/7/2018SundayEast  
1/7/2018SundayWest  
1/8/2018MondayCentral200150
1/8/2018MondayEast100 150
1/8/2018MondayWest50 175
1/9/2018TuesdayCentral100 
1/9/2018TuesdayEast200225
1/9/2018TuesdayWest300 

 

 

Super User IV
Super User IV

Re: How to calculate conditional running totals in Power BI?

Hi,

 

Why have you left the other cells in the Avg_MTD_Weekoftheday empty?  Is tha intentional or is there a logic for them to be left empty?


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

Re: How to calculate conditional running totals in Power BI?

I Want to calculate that field as I mentioned. I just gave couple of example what the answer to that field look like. 

 

EG, Monday MTD Avg or Monday YTD Avg.

 

For the first week of the month it will be same as CallCount, From second week it will start calculating that field , AVG of Current monday and previous mondays.

Super User IV
Super User IV

Re: How to calculate conditional running totals in Power BI?

Hi,

 

Enter this calculated field formula

 

=if(ISBLANK(Data[CallCount]),BLANK(),CALCULATE(AVERAGE(Data[CallCount]),FILTER(Data,Data[WeekofDay]=EARLIER(Data[WeekofDay])&&Data[Region]=EARLIER(Data[Region])&&Data[Date]<=EARLIER(Data[Date]))))

 

 


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

Helpful resources

Announcements
Announcing the New Spanish Forum

Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

April 2020 Community Highlights

April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Top Solution Authors
Top Kudoed Authors