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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Showing date range for Current period and previous period based on selected date range

Hi all,

i am having data from Jan 2018 to May 2021

I am currently showing KPIs for a selected range of data which i am using it in a date slicer (between).
i am able to get the selected min date and max date from the dax

var _mindate=min(calander[date])
var _maxdate=max(calander[date])

and i am showing the range for current selected period by

COMBINEVALUES("-",FORMAT(_mindate,"mmm yyyy"),FORMAT(_maxdate,"mmm yyyy"))
for ex: Selected period is from Jan 19 to Dec 19
Current period date range is
mathivananj_0-1633335148024.png

Now here i am facing issue showing the date range.

When i select Sep 18 to Aug 19 

Current Year is 

mathivananj_1-1633335344090.png

 

For the previous year range label , i have only data from jan 18 but 
when i use this measure 

Previousperioddaterange =
var _mindate=CALCULATE([Mindate],SAMEPERIODLASTYEAR(Calander[Date]))
var _maxdate=CALCULATE([Maxdate],SAMEPERIODLASTYEAR(Calander[Date]))
var PreMindt=FORMAT(_mindate,"mmm YYYY")
var PreMaxdt=FORMAT(_maxdate,"mmm YYYY")
return
COMBINEVALUES("-",PreMindt,PreMaxdt)
but this works only for only avaliable date, but i want to show if there is no data on that month i want to show blank or just say Previous period.

 

2 REPLIES 2
VahidDM
Super User
Super User

Hi @Anonymous 

 

Try this measure:

Previousperioddaterange =
var _mindate=CALCULATE([Mindate],SAMEPERIODLASTYEAR(Calander[Date]))
var _maxdate=CALCULATE([Maxdate],SAMEPERIODLASTYEAR(Calander[Date]))
var PreMindt=if(_mindate>=[Mindate],FORMAT(_mindate,"mmm YYYY"),blank())
var PreMaxdt=if(isblank(PreMindt),blank(),FORMAT(_maxdate,"mmm YYYY"))
return
COMBINEVALUES("-",PreMindt,PreMaxdt)

 

You can find the previous period regardless of available date, with this code:

Previousperioddaterange =
Var _Min = [Mindate]
Var _Max = [Maxdate]
var _mindate=date(year(_Min)-1,month(_Min),day(_Min))
var _maxdate=date(year(_Max)-1,month(_Max),day(_Max))
var PreMindt=FORMAT(_mindate,"mmm YYYY")
var PreMaxdt=FORMAT(_maxdate,"mmm YYYY")
return
COMBINEVALUES("-",PreMindt,PreMaxdt)

 

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

Appreciate your Kudos!!

 

Anonymous
Not applicable

Hi @VahidDM 

 

I have tried first one its not suitable for my problem, and second one is working fine but in my data i have range from Jan 2018 to May 2021. So if i select a current date range of July 2018 - Dec 2018 it should show "No data" but its showing July 2017 - Dec 2017 for which i dont have a data.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.