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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
maxduff59
Helper II
Helper II

Plot a graph between two dates

I created two measures which contain : the date of the day and the date of x days before today (x chosen with a slicer).
I would like to plot a graph with some dates on x-axis and numeric values on y-axis.

Do you have an idea how could I filter my axis between my two dates measures ? 

Thanks in advance for your help and your time

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@maxduff59 if you will create a measure like:
MEASURE = 
VAR _x_days_before_date = [Your Date x days before Measure]
VAR _date =  [your the date of the day Measure]
RETURN
CALCULATE([Your value], DATESBETWEEN('Date Table'[Date], _x_days_before_date,  _date] 

You would get the y values only for those dates, everything outside will be blank and not presented on the chart and axis will start from your desired start to end.



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

5 REPLIES 5
SpartaBI
Community Champion
Community Champion

@maxduff59 if you will create a measure like:
MEASURE = 
VAR _x_days_before_date = [Your Date x days before Measure]
VAR _date =  [your the date of the day Measure]
RETURN
CALCULATE([Your value], DATESBETWEEN('Date Table'[Date], _x_days_before_date,  _date] 

You would get the y values only for those dates, everything outside will be blank and not presented on the chart and axis will start from your desired start to end.



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

I will try that, thank you. I just have a little question, why do I need to redefine my date measures through variables ?
Moreover, what is the first term of the CALCULATE function [YOUR VALUE] ? 

@maxduff59 variables are always good thing to use for code readability and better performance. In some cases you must use them cause sometimes if you put your measures inside another calculate filter argument you might not get what you want.
Of course you can't use, btw, variables as something to put in the 1st argument of calculate cause they are already been executed. 
Actually, yesterday came out a cool video I recommend to watch:
https://www.youtube.com/watch?v=NbbE39gwVVo


Please don't forget to accept the relevant messages as a solution for community visibility. P.S. Check out my showcase report - got some high level stuff there. Sure you will find there a lot of cool ideas. Please give it a thumbs up over there if you liked it 🙂 https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Thanks for the explications, I just don't understand which term do I need to put first in the CALCULATE function...

you put there an aggregation expression ususally, and you can also call a measure instead. The think I meant that in this case you can't use a var before it and call it inside. But I think the video explains it better. 
Let me know that is what you meant.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.