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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
thanish
Frequent Visitor

User input for the start date

Below is a scenario I have in MMDDYYYY format

Start DateEnd DateUnit_PriceQuantityTotalPrice
1/1/20156/1/201520011000
     

 

Consider the above is the sample of rental price of the product for the given period. Unit_price is the rental price for a month. From the start date and end date it constitutes to 5 months which would give the Total price/revenue of 1000 to the compay.

 

Now my company generates report monthly/many months together to find out how much a particular product has been generating. 

I can create a start date filter using the filter chart and bar chart with months/Date in x-axis and unit_price in y-axis.

 

If I click on January in the filter my bar chart will map to the Start Date column for x-axis and Unit_Price for Y-axis. But what would be if I click for the months February or March or April or May since those months are not in either Start Date or End Date column ?

 

Sometimes my management would like to know the revenue for months from Feb to May (4 months). In that case the total revenue should be 800, Is there a way in PowerBI to do such calculations ? 

 

Is there a way user can give the date(end date) and then calculate the period subtracting from the start date ?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @thanish,

 

According to your description, you want to use slicer choose an end date instead of filter data, right?

If it is a case, you can follow below steps:

 

Data table:

Capture2.PNG
 

Calendar table: (not related to data table)
DateTable = CALENDAR(MIN(Sheet1[Start Date]),MAX(Sheet1[End Date]))

Capture3.PNG
 

Measures.

 

Use to get the select date:
Selected End data =
var currentEnddate=MAX(Sheet1[End Date])
return
if(HASONEVALUE(DateTable[Date]),VALUES(DateTable[Date]),currentEnddate)

 

calculate the data range and the total price:
Total Price =
var unit=MAX(Sheet1[Unit_Price])
var qty=MAX(Sheet1[Quantity])
var startDate= MAX(Sheet1[Start Date])
var endDate= MAX(Sheet1[End Date])
return
CALCULATE(if(AND([Selected End data]<=endDate,[Selected End data]>=startDate), DATEDIFF(startDate,[Selected End data],MONTH),if([Selected End data]<startDate,0,DATEDIFF(startDate,endDate,MONTH))) * unit * qty,ALLSELECTED(Sheet1))

 

Create visuals.

Slicer:

Capture4.PNG
 

Table visual:
Capture5.PNG 

 

Result:

 Capture6.PNGCapture7.PNGCapture8.PNG


  

Comment of formula:


if(AND([Selected End data]<=endDate,[Selected End data]>=startDate), DATEDIFF(startDate,[Selected End data],MONTH),if([Selected End data]<startDate,0,DATEDIFF(startDate,endDate,MONTH)))

 

if “selected date” is between “startdate” and “enddate”, get the date range to calculate. If “selected date” less than “start date”, set date range to 0. If “selected date” greater than “enddate” set the date range to old range.

 

If above is not help, please feel free to post.

 

Regards,
Xiaoxin Sheng

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @thanish,

 

According to your description, you want to use slicer choose an end date instead of filter data, right?

If it is a case, you can follow below steps:

 

Data table:

Capture2.PNG
 

Calendar table: (not related to data table)
DateTable = CALENDAR(MIN(Sheet1[Start Date]),MAX(Sheet1[End Date]))

Capture3.PNG
 

Measures.

 

Use to get the select date:
Selected End data =
var currentEnddate=MAX(Sheet1[End Date])
return
if(HASONEVALUE(DateTable[Date]),VALUES(DateTable[Date]),currentEnddate)

 

calculate the data range and the total price:
Total Price =
var unit=MAX(Sheet1[Unit_Price])
var qty=MAX(Sheet1[Quantity])
var startDate= MAX(Sheet1[Start Date])
var endDate= MAX(Sheet1[End Date])
return
CALCULATE(if(AND([Selected End data]<=endDate,[Selected End data]>=startDate), DATEDIFF(startDate,[Selected End data],MONTH),if([Selected End data]<startDate,0,DATEDIFF(startDate,endDate,MONTH))) * unit * qty,ALLSELECTED(Sheet1))

 

Create visuals.

Slicer:

Capture4.PNG
 

Table visual:
Capture5.PNG 

 

Result:

 Capture6.PNGCapture7.PNGCapture8.PNG


  

Comment of formula:


if(AND([Selected End data]<=endDate,[Selected End data]>=startDate), DATEDIFF(startDate,[Selected End data],MONTH),if([Selected End data]<startDate,0,DATEDIFF(startDate,endDate,MONTH)))

 

if “selected date” is between “startdate” and “enddate”, get the date range to calculate. If “selected date” less than “start date”, set date range to 0. If “selected date” greater than “enddate” set the date range to old range.

 

If above is not help, please feel free to post.

 

Regards,
Xiaoxin Sheng

 

BhaveshPatel
Community Champion
Community Champion

So as per my understaning you would like to create a running total for the particular period. 

 

If that is the case, Please refer to the below blog post.

 

https://javierguillen.wordpress.com/2012/11/28/running-total-techniques-in-dax/

 

 

Thanks & Regards,

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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