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
nachoroncero
Frequent Visitor

Show only curren year month values

Hello,

 

This is an example of my dataset. I have values of everymonth since Jan-2017 to Dec-2019 with this shape.

nachoroncero_0-1646299008218.png

I would like to use a chart line showing only YTD data.

Example:

I have a slicer where I select one specific month, if I choose that month, I want data from Jan. from that year to the selected month only. I choose May 2018, I only want to see data from Jan.2018 to May 2018 in my chart, how can I do that?

 

Thank yo for your time

 

1 ACCEPTED SOLUTION
moizsherwani
Continued Contributor
Continued Contributor

First create a calendar table by going to Modelling->New Table and paste the following

(you must ensure that the newly created calendar table is not connected to the data table which you can do by checking the Model view)

Calendar = 

var _fromYear=year(FIRSTDATE(DummyData[Date])) 
var _toYear=year(LASTDATE(DummyData[Date]))   

return
ADDCOLUMNS(
    CALENDAR(
                DATE(_fromYear,1,1),
                DATE(_toYear,12,31)
),

"Start of Month",DATE( YEAR([Date]), MONTH([Date]), 1)
)

 

Next create a measure 

 

SumValuesYTD =
VAR EndDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
VAR EndDateYear =
    YEAR ( EndDate )
VAR StartDate =
    DATE ( EndDateYear, 1, 1 )
RETURN
    CALCULATE (
        SUM ( DummyData[Values] ),
        FILTER ( DummyData, DummyData[Date] >= StartDate && DummyData[Date] < EndDate )
    )

 

For the slicer use the "Calendar" "Start of Month" Field and for the visual (table/graph) use the Data Field (see screenshot below).

 

Screenshot 2022-03-03 232116.png

 

Let me know if this helps

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

View solution in original post

8 REPLIES 8
moizsherwani
Continued Contributor
Continued Contributor

First create a calendar table by going to Modelling->New Table and paste the following

(you must ensure that the newly created calendar table is not connected to the data table which you can do by checking the Model view)

Calendar = 

var _fromYear=year(FIRSTDATE(DummyData[Date])) 
var _toYear=year(LASTDATE(DummyData[Date]))   

return
ADDCOLUMNS(
    CALENDAR(
                DATE(_fromYear,1,1),
                DATE(_toYear,12,31)
),

"Start of Month",DATE( YEAR([Date]), MONTH([Date]), 1)
)

 

Next create a measure 

 

SumValuesYTD =
VAR EndDate =
    CALCULATE ( MAX ( 'Calendar'[Date] ), ALLSELECTED ( 'Calendar' ) )
VAR EndDateYear =
    YEAR ( EndDate )
VAR StartDate =
    DATE ( EndDateYear, 1, 1 )
RETURN
    CALCULATE (
        SUM ( DummyData[Values] ),
        FILTER ( DummyData, DummyData[Date] >= StartDate && DummyData[Date] < EndDate )
    )

 

For the slicer use the "Calendar" "Start of Month" Field and for the visual (table/graph) use the Data Field (see screenshot below).

 

Screenshot 2022-03-03 232116.png

 

Let me know if this helps

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Thank ou ver much for your time and solution. It works as expected!

nachoroncero
Frequent Visitor

I am using this slicer.

nachoroncero_0-1646300861338.png

 

Which table is this Mes Seleccionado coming from, the same table as the data (fact table) or is there a seperate calendar table (dimension table) which it is from?

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

from the same table, the one I showed above in the first message. It all bellongs to it.

I want to use the fecha column (Date in English) and the mensual column that contains the values I want to display for the specific dates

@nachoroncero Are you able to create a new table (supporting calendar table) or a new column if the solution required it?

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

Yes, I could

moizsherwani
Continued Contributor
Continued Contributor

@nachoroncero  are you using a calendar table to select the month or just selecting it from the data table itself?

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.